foreach (@b){ for $item (@a){ push(@c, $item) if grep {$item =~ m/$_/} @b;}} print "@c";