use strict; use warnings; use v5.12; use constant TOP => 1000000; say "1 is prime."; say "2 is prime."; my $found = 2; # We already found 1 and 2. OUTER: for( my $i = 3; $i < TOP; $i += 2 ) { for( my $j = $i - 2; $j > 1; $j -= 2 ) { ( not $i % $j ) && next OUTER; } say "$i is prime."; $found++; } say "Found $found primes between 1 and ", TOP, ".\n";