s/(\d)/$s+=$1/ge; # $s is the sum... # Which leaves garbage in $_, but is a single stroke shorter than: $s+=$_ for split//; # But thenagain, this is even shorter: $s+=$_ for/./g;