use Try::Tiny; try { ... $sth->execute(); ... } catch { # $sth->err and $DBI::err will be true if error was from DBI warn $_; # print the error (which Try::Tiny puts into $_) ... # do whatever you need to deal with the error };