As well as possible quoting issues, as mentioned by
aquarium (I usually quote using a qq or q around the entire SQL statement, and DBI also provides its own quote method), make sure that RaiseError is set to 1 on the database handle, otherwise $@ might not contain anything useful.