use Benchmark qw(:all) ; my $test_element = 42_000; my @a = (1..100_000); my $count = 20; cmpthese($count, { 'hash' => sub { my %seen; undef( @seen{ @a } ); # a trick I learned from tilly my $found = 0; for my $iter (10_000..10_100) { # 101 searches $found = 1 unless exists $seen{ $iter }; } return $found; }, 'for' => sub { my $found = 0; for my $iter (10_000..10_100) { # 101 searches foreach (@a) { $found = 1 and last if $iter == $_; } } return $found; }, });