in reply to Re^2: Array compare using elements as the pattern match.
in thread Array compare using elements as the pattern match.

Alternately:

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

For exact matches, index will be faster.

A more Perl-ish way:

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

Replies are listed 'Best First'.
Re^4: Array compare using elements as the pattern match.
by toolic (Bishop) on Dec 13, 2014 at 02:55 UTC
    Why do you consider that a "more Perl-ish way"? Your grep traverses the entire array every time, whereas my for/last only traverses until it finds a match.