eval { local $SIG{ALRM} = sub (die "timeout\n"); alarm 5; telnet_connect: #label for later handling of dropped sessions my $t = new Net::Telnet(); # Even with the new() line above the alarm fires # Adding the lines below stop the alarm from working $t->open($host) $t->login($user, $pass); while (1) { # Interact w/telnet session until we're happy # This loop is always reached in testing } $t->close() alarm 0; }; if ($@) { if ($@ =~ /timeout/) { print "Timed out!"; } else { print "Received exception: $@\n"; alarm 0; die; } }