Multi-level sort in Perl