I log all incoming connections to my opennap server to a postgres database. I get about 625,000 connections per day, and I wanted to sort them by domain so that I could see visually in text where they were coming from. So I'll spare you the database calls. This, however, was a cool little hack to print the hosts out sorted by domain (rather than hostname). You can easily use File::Slurp to write the scalar obtained.
I have a feeling this has a speed increase. It's a Guttman-Rosler Transform, which means that the sorting is done by the native sort(). Also, I only reverse each key twice, whereas your method is probably doing a lot more reversing.