1. Divide and accumulate:
my $x=3456; my $sum=0; while ($x) { $sum+=$x%10; $x/=10; } print $sum;The digits are extracted by taking the modulus of the number with 10, and then dividing the number by 10. This is repeated till the original number becomes zero at the end of which the sum is retrieved.