for my $pattern (@gen) { my @result = grep/^\Q$pattern\E$/, @sea; push (@final , @result); }