in reply to Problem Converting SQL term to Perl Variable
When you have a mystery error like this, try to verify at each step that things are what you expect. In this case, that would mean printing $sql and comparing it to your working mysql prompt query.