use strict; my $max = $ARGV[0] || 100; my @primes = ( 2 ); for my $num ( 3 .. $max ) { my $sqrt = sqrt $num; for my $prime ( @primes ) { last unless $num % $prime; push @primes, $num and last if $prime > $sqrt; } } print join ", ", @primes; print "\n";