# use strict; # use warnings; sub sumNumsInStr { my $s = shift; my $c = 0; foreach(0 .. (length($s) - 1)) { my $x = substr($s, $_, 1); $c += int($x) if ($x ge '0' && $x le '9'); } return $c; } chomp(my $s = <>); print(sumNumsInStr($s), "\n");