$sth->execute(); # $sth is the statement-handle if ($dbh->errstr && $dbh->errstr =~ /Relation\s[a-zA-Z_-']+\salready\sexists/) { # $dbh is the db-handle die ... }