my $pid = open my $calc, '-|', "$command 2>&1" or die "Pipe failed on open: $!\n"; local $SIG{ALRM} = sub { kill 9, $pid; die "Calculation call failed to return with $timeout seconds\n"; }; alarm $timeout; local $/; # Slurp my $content = <$calc>; close $calc; alarm 0;