$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);