for my $ref (sort {substr($a,1) <=> substr($b,1)} grep {substr($_,0,1) eq 'A'} @array) { #whatever with $ref }