#!usr/bin/perl use say; use strict; use warnings; # use Benchmark qw(:all) ; # WindowsOS use Benchmark::Forking qw( timethese cmpthese ); sub while_loop { my (@array) = @_; while (defined(my $i = shift @array)){ # This destroys @array, though next if ($i % 2 || $i % 3 || $i % 4 || $i % 5); } } sub for_loop { my (@array) = @_; foreach my $i ( @array ) { # This does not destroy the @array next if ($i % 2 || $i % 3 || $i % 4 || $i % 5); } } my $results = timethese(100000000, { For => for_loop( 1 .. 100 ), While => while_loop( 1 .. 100 ) }, 'none'); cmpthese( $results ); __END__ $ perl test.pl (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate For While For 434782609/s -- -83% While 2500000000/s 475% --