DBI->connect(....) || fatal(error message) #### sub openDB { my ($database, $user_id, $password) = (); open( CFG, $db_cfg ) or fatal("Cannot open databse config file."); ($database, $user_id, $password, $pwkey) = split( ',', ); $done = 0; $num_tries = 0; while (!$done) { $num_tries += 1; # If we exceeded the custom amount of attempts call error routine if ($num_tries > 4) { fatal (" Could not open database: $DBI::errstr"); $done = 1; } else { # Make the database connection eval { $dbh = DBI->connect("DBI:mysql:$database:", $user_id, $password); } # If there is an error try again if ($@) { next; } # No error drop out of loop else { $done = 1; } } } }