in reply to Sorting by Value

As far as writing out the solution for you, I will not for I am having a hard time deciphering your post in the first place.

However, sorting a hash in reverse by value as opposed to by key is as simple as:

my %hash = ( 'A' => 5, 'B' => 4, 'C' => 3, 'D' => 2, 'E' => 1 ); for my $key (sort { $hash{$b} <=> $hash{a} } keys %hash) { #... }

I believe will give you the desired effect. Try perldoc -q sort on the command line for more details.