in reply to Nested loops?

Why are you doing a SQL task in perl? Just let the database do the whole thing for you. It's faster, an will save on network traffic.

Please post the queries so we can have a look at combining them.