Many others have suggested hashes, and that's definitely a valid approach. I'm curious, though, whether you couldn't achieve the same thing in SQL. That is, maybe you should just create a single query JOINing the two queries on service_id. That might reduce the amount of data you need to pull into Perl, and let the SQL server do the heavy lifting for you (which is what it's good at, after all).