for (@array2) { for my $pat (@array1) { if (index($_,$pat) > -1) { push @a3, $_; last; } } }