It would help to see not only the SQL statement, but also how exactly you embed it into Perl. I think there might be the real problem. If you print out the SQL statement Perl has right before calling prepare, does it look exactly as the one you showed ?