in reply to Sorting a Hash

The solution was in using the substr function together with the cmp operator to get the intended output.
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..... .......... }