in reply to Complex Sorting/Reporting

With the right tool, this becomes a simple problem. Given the data above, the right tool is a relational database with a report writer. Whatever your feelings about Microsoft, MS Access makes quick work of stuff like this.

Or try MySQL, though you'll have to do the report writing yourself, though having SQL will do half the work.

Or, depending on what platform you're on, you might be able to use DBI::SQLite for a Perl-only database.