See options $dbi->{'RaiseError'} and $dbi->{'PrintError'}, querrying on a dead database will always throw an error or a warning respectively. If you set RaiseError to 1, and set PrintError to 0 (default), and capture the error message from $DBI::stderr after an eval, you can run a regex to see if it matches that of a failed connection, if it fails, reconnect and try again.