in reply to sorting hash of hashes

Your inmost loop looks suspicious - you repeat the same expression as its predecessor.

I usually find it helps when dealing with a complicated datastructure to run the program in the debugger. That way you can experiment with syntax to get the part you want.

Dum Spiro Spero