sub match_arrays2{ # gmax my ($elem, $find) = @_; my @regex_find = map {qr /#$_#/} @$find; my @match = (); my $elem_join = '#' .join('#',@$elem) . "#"; for (@regex_find) { push @match, undef if $elem_join =~ /$_/ ; } return @match == @$find; } __END__ Benchmark: timing 500 iterations of hash, join, join2, set... hash: 15 wallclock secs (14.66 usr + 0.06 sys = 14.72 CPU) join: 1 wallclock secs ( 1.27 usr + 0.00 sys = 1.27 CPU) join2: 2 wallclock secs ( 1.27 usr + 0.00 sys = 1.27 CPU) set: 10 wallclock secs ( 9.89 usr + 0.04 sys = 9.93 CPU) Rate hash set join join2 hash 34.0/s -- -33% -91% -91% set 50.4/s 48% -- -87% -87% join 394/s 1059% 682% -- 0% join2 394/s 1059% 682% 0% --