use Benchmark; $build = <<'BUILD'; my @a = (0..10000); my @b = (9000..19000); BUILD $iterate = <<'ITERATE'; my @a = (0..10000); my @b = (9000..19000); my (@matches,@mismatch); @matches = @mismatch = (); foreach $a (@a) { push @matches, $a if grep{$a == $_}@b; } foreach $a (@a) { push @mismatch, $a unless grep{$a == $_}@b; } ITERATE $hash = <<'HASH'; my @a = (0..10000); my @b = (9000..19000); my (@matches,@mismatch); @matches = @mismatch = (); map{$seen{$_}++}@b; @matches = grep{defined $seen{$_}}@a; @mismatch = grep{!defined $seen{$_}}@a; HASH timethese(1,{ 'build' => $build, 'iterate' => $iterate, 'hash' => $hash }); __END__ C:\>perl test.pl Benchmark: timing 1 iterations of build, hash, iterate... build: -1 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU) (warning: too few iterations for a reliable count) hash: 0 wallclock secs ( 0.16 usr + 0.00 sys = 0.16 CPU) @ 6.25/s (n=1 ) (warning: too few iterations for a reliable count) iterate: 147 wallclock secs (147.20 usr + 0.00 sys = 147.20 CPU) @ 0.01/s ( n=1) (warning: too few iterations for a reliable count) C:\>