in reply to MySQL - Query vs Perl

Have a rethink of your database design. It does not look normalised at all. Your 'mess' should vanish after splitting it up into several tables.

Then it is time to read up on persistence, e. g. Class::DBI.