#!/usr/bin/perl @not_sorted = qw(Ape Arg Beep Circus); @sorted = sort {$a cmp $b} @not_sorted; @A = (); @trash = (); foreach(@sorted) { if(substr($_,0,1) == 'A') { printf($_." added to A\n"); push(@A, $_); } else{ printf($_." added to trash!\n"); push(@trash, $_); } } print join(', ', @A)."\n"; print join(', ', @trash)."\n";