$TIMEOUT = 5; $CMD = $ARGV[0]; eval { $SIG{ALARM} = sub { die "TIMEOUT\n" }; alarm $TIMEOUT; system($CMD); alarm 0; }; # do error processing