my $dbh; eval { $dbh = DBI->connect($dsn, $stuff, { RaiseError => 1 }); # will die if it doesn't work } if ($@) { # you can process the error string in $@ and clean it up # for output print $error; }