... my $dbh; eval { $dbh = DBI->connect(...); }; if ( $@ ) { # do something with the error }