in reply to Sorting a Hash
foreach my $p ( sort { substr($$a{GRADE},0,1) cmp substr($$b{GRADE}, +0,1) || substr($$b{GRADE},0,2) cmp substr($$a{GRADE} +,0,2)} @{$AG{$A}}) { output D2 D1 P5 P5 P4 P3 P3 P2 P1 etc..... .......... } [download]