in reply to 3 dimensional hashes!
This is the type thing that an RDBMS excells at. Just throw the data into one (even DBD::SQLite would probably suffice) and then select the counts using GROUP BY apropriately.