my $db; eval { local $SIG{ALRM} = sub { die "connect timeout\n" }; alarm 15; $db = DBI->connect("DBI:Oracle:".... ) or die $DBI::errstr; alarm 0; }; if ($@) { # timed out die unless $@ eq "connect timeout\n"; } elsif (!$db) { # didn't connect die "no database connection\n"; } # $db is ok here