eval { $db = DBI->connect("dbi:mysql:database="$remotedb"; host=127.0.0.1;port=$port", "$user", "$pass", { RaiseError=>1, PrintError=>0 } ); }; if ($@){ #handle db error (ie, host not available.. blah blah }else{ return $db; }