As Anonymous Monk suggested, switch to using place holders instead of manifest strings in the SQL. Also, if you aren't already, make sure you are using strictures (use strict; use warnings; - see The strictures, according to Seuss). They will pick up dodgy code and run time errors such as using undef variables in inappropriate ways.
If your problem persists try writing a little test script, maybe using SQLite instead of MySQL (because it's just a CPAN install - no server needed), that demonstrates the issue.
Perl is the programming world's equivalent of English