as seen in perldoc perlipc
#!/usr/bin/perl use warnings; my @cmd = @ARGV; my @ls = (); my $t = 10; eval { local $SIG{ALRM} = sub { die "alarm went off" }; alarm $t; @ls = `@cmd`; alarm 0; }; if (! @ls) { print "No response after $t seconds\n"; } else { foreach (@ls) { print $_; } } # actually never gets to here if ($@ and $@ !~ /alarm went off/) { die "Command timed out after $t seconds\n"; };