in reply to Capturing SQL errors in Perl

$dbh->errstr should give you what you want.

As moritz suggested, using exceptions can simplify your logic:

$dbh->{RaiseError} = 1; # only need to do this once ... eval { my $sth = $dbh->prepare(...); $sth->execute(...); }; if ($@) { # unable to insert, error message is in $@ ... }
Also, please use placeholders!