for my $ref (sort grep /^A/, @array) { #whatever with $ref }