my @matches = grep { /$pattern/ } @names; #### my @matches = grep { $names[$_] =~ /$pattern/ } 0..$#names;