eval { local $SIG{ALRM} = sub { die "timeout\n" }; alarm(2); $t = new Net::Telnet (Host => $host, Port => $port, Timeout => 1, Prompt => '/Escape character is.+\n/', Rs => ' ', Ors => '', Binmode => 1, Telnetmode => 1, Errmode => 'return'); alarm(0); }; if ($@) { die $@ unless $@ eq "timeout\n"; warn "Timed out!\n"; }