if ($#Terms > 0) { print "HERE\n"; # to confirm this takes place; @Notes = sort { $b->{terms} <=> $a->{terms} } @Notes; } my @Sorted = sort { $b->{terms} <=> $a->{terms} } @Notes; print "$#Notes $#Sorted\n"; for (my $i = 0; $i<=$#Notes; $i++) { print $Notes[$i]->{terms}.$Sorted[$i]->{terms}."\n"; } #### HERE 1008 1008 12 12 12 12 12 [..etc: nb, there is never anything other than 1 or 2]