my $dbh = DBI->connect(...) or handle_connect_fail($DBI::errstr); sub handle_connect_fail { my ($error) = shift; # print loud warnings, # maybe sleep 300 and retry. # Or use mail send module, and have your script page you. }