use strict; use warnings; use Benchmark qw{ cmpthese }; my @arr = ( 1 .. 1e6 ); my $rcOneElement = sub { my $aref = shift; sub { my $var = shift }->( $_ ) for @$aref; }; my $rcAllElements = sub { my $aref = shift; sub { my $var = shift while @_ }->( @$aref ); }; cmpthese ( -5, { OneElement => sub { $rcOneElement->( \ @arr ) }, AllElements => sub { $rcAllElements->( \ @arr ) }, } ); #### Rate OneElement AllElements OneElement 2.59/s -- -58% AllElements 6.16/s 138% --