$cmd="myCommand"; # Timeout evaluation: eval { # Set action to be done when alarm occurs: local $SIG{ALRM} = sub { die "ALARM_COMMAND_TIMEOUT" }; # Schedule alarm in $CMD_TIMEOUT seconds: alarm($CMD_TIMEOUT); ### execute the command that can block $Results = `$cmd`; if ($?) {# optional error handling} } wait; alarm(0); close(PIPE); }; alarm(0); #### perl -le'$SIG{ALRM}=sub {die "TIMEOUT"}; eval{alarm 10; open PIPE, "while [ 1 ] ;do echo \"foo\";sleep 5;done|"; while (){print}}; print $@'