use Modern::Perl; use Time::HiRes qw/time/; my $start = time; my $top = 550; my $max = 100; my @primes; my $prime; for ( 2 .. $top ) { $prime = $_; next if $primes[$_]; last unless --$max; { local $_; $primes[ $_ * $prime ] = 1 for 2 .. $top / $prime; } } my $found = time; say $_ for ( grep { !$primes[$_] } 2 .. $prime ); my $end = time; say sprintf "Found all: %.6f seconds", ( $found - $start ); say sprintf "Printing all: %.6f seconds", ( $end - $found ); say sprintf "Running time: %.6f seconds", ( $end - $start );