in reply to file ext counter.

While I applaud your use of references to create complex data structures, you can save some memory and speed by operating on the hash directly:
sub sort_by_value { my $hash = shift; sort {$hash->{$a} <=> $hash->{$b} } keys %$hash; }
I won't ask why you declare @keys and then immediately clobber it. :) (I often forget to delete test code, too.)