in reply to Error "'exists ^0^' has chars not alphanumeric or underscore in perl"
choroba is correct. I managed to see the % in the SQL string and had a knee-jerk reaction.
The problem is that you're trying to interpolate variables into SQL rather than using placeholders. Read up on placeholders in DBI and convert your code to use them. It'll simplify things for you, make your code more robust, and prevent odd SQL syntax problems.
When your only tool is a hammer, all problems look like your thumb.