for (map "A$_", sort { $a <=> $b } map /^A\d+$/ ? substr($_,1) : (), @array) { ... #### for (sort grep /^A/, @array) { ...