in reply to alarm() killing my program

I am not certain that's the best way to use alarm. Typically, people set the $SIG{ALRM} handler to a sub which throws an exception, then the main body of code is in an eval so the alarm gets trapped properly. Also, use local so you don't lose library definitions of alarm handler.
sub poll { # execute code with timeout eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm 30; # alarm in 30 seconds # your code here (could timeout) alarm 0; # cancel alarm }; if ($@) { die $@ unless $@ eq "alarm\n"; # propagate unexpected errors # take action for timeout } }