my @kansas = qw( corn wheat hay cattle ); my @oklahoma = qw( wheat dairy cattle ); use Benchmark; timethese(100000, { "diff1" => sub { diff1(\@kansas, \@oklahoma) }, "diff2" => sub { diff2(\@kansas, \@oklahoma) }, }); sub diff1 { my %hash; @hash{@{$_[1]}} = (1) x @{$_[1]}; return grep { !defined $hash{$_} } @{$_[0]}; } sub diff2 { my %hash = map{ $_=>1} @{$_[1]}; return grep { !defined $hash{$_} } @{$_[0]}; }