# Assumes RaiseError is set eval { $dbh->do("insert ...."); }; if($@) { # check for the "duplicate insert" error here, and # handle accordingly... }