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