sub db_keepalive { # if connection is dead if(!$dbh->ping) { # reopen it $dbh = DBI->connect_cached($data_source, $username, $password, \%attr) or die $DBI::errstr; } }