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