$SIG{ALRM}=\&alrm_handler; sub alrm_handler { do...something here... sounds like die and cause shell command to be re-executed... } my $inLine; while (alarm(20), $inLine = <> and $inLine !~ /^Done/) { alarm(0); # deactivate the alarm!! normal loop here... } print "Exiting\n"; exit;