eval { $dbh->do(...); }; if (my $e = $@) { if ($dbh->{Active} != 1 || $dbh->state =~ /08\d{3}/){ # reconnect and retry } else { # not connection related error } }