# @array1 and @array2 are what are tested my %test; map {$test{$_}=undef} @array1; my @result; foreach (@array2) { push (@result,$_) if (exists($test{$_})); }