for my $a (@array1) { for my $b (@array2) { next if $a ne $b; # Do whatever tests you need here # Do the work here } }