a_short_circuit_foreach => sub { my $present; foreach( 0..100 ) { if( /0/ ) { $present++; last } } $present }, #### #!/usr/bin/perl use Benchmark qw( timethese cmpthese ); my @data = ( 0 .. 100 ); my %cheat; @cheat{ @data } = (1) x @data; my @args = ( -1, { void => sub { grep /50/, @data; 1 }, scalar => sub { my $res = grep /50/, @data }, list => sub { my @res = grep /50/, @data }, a_foreach => sub { my $match; foreach( @data ) { $match++ if /50/ } $match }, a_short_circuit_foreach => sub { my $present; foreach( @data ) { if( /50/ ) { $present++; last } } $present; }, a_hash => sub { exists $cheat{ 50 }; } } ); cmpthese( @args ); exit 0; __END__