use warnings; use strict; use Time::HiRes qw/ tv_interval gettimeofday/; my $time0 = [gettimeofday]; use warnings; use strict; my $max = 100; my @primes = ( 2, 3 ); #seed the primes my $this = $primes[-1]; while ( $max > scalar @primes ) { $this += 2; my $sqrt = $this**.5; for (@primes) { if ( $_ > $sqrt ) { push @primes, $this; last; } next if $this % $_; last; } } my $elapsed = tv_interval( $time0, [gettimeofday] ); print "Printing the first $max numbers that are prime... \n"; print "$_ is prime.\n" for @primes; print "Took $elapsed seconds.";