Comments : you seem to never use $length for anything interesting -- just as an added layer of complexity to your %word hash. You can remove it when referring to %words keys and achieve the same results : push @{$word{$sorted_word}}, $_;
and so on.
Also, you can replace