# instead of system("/foo/bar") do... my $pid = fork; if (defined $fork and not $fork) { alarm $timeout; exec "/foo/bar"; exit(1); # just in case exec fails. }