use strict; use warnings; my @not_sorted = qw(Ape Arg Beep Circus); my @sorted = sort {$a cmp $b} @not_sorted; my @A = grep { /^A/ } @sorted; my @trash = grep { !/^A/ } @sorted; print join(', ', @A) , "\n"; print join(', ', @trash) , "\n";