for my $pattern (@array2) { my @results = grep /$pattern/, @array1; print "$pattern is in @results\n"; }