eval { local $SIG{ALRM} = sub { die "Bad rx timed out" }; alarm 5; # start the timer eval { # the user's rx is run here... }; alarm 0; # clear the timer }; alarm 0; # in case something else went wrong die $@ if $@ and $@ !~ /rx timed out/;