in reply to Finding sum of all digits from 1 to 1 million.

Ummm... You're actually close, although you're off by 1. Fencepost error - you're terminating the loop one too early, so you're not including 1e6 in the loop. When in doubt, let perl figure out the right way to do it for you:

A slightly modified version:

#!/usr/bin/perl -w use strict; # or die :-) my $LIMIT = 1000000; my $s; foreach (1 .. $LIMIT) { foreach (/./g) { $s += $_; } } print "Sum: $s\n";

Golfers invited to make this even nicer (not to mention make it run faster...)