in reply to Threads or no Threads

Here's a rather simple solution that may work for you.

#! perl -slw use strict; our $WAIT ||= 10; my $cmd = 'perl -e"$|++;sleep 1, print for 1 .. 10" |'; my $pid = open my $cmdFh, $cmd or die "Couldn't run '$cmd': $!"; sleep 1 while kill 0, $pid and $WAIT--; kill 3, $pid and warn 'Command timed out' if $WAIT; my $results = do{ local $/; <$cmdFh> }; print "Got: '$results'";

A few simple tests

c:\test>junk9 -WAIT=2 Command timed out at c:\test\junk9.pl line 11. Got: '12' c:\test>junk9 -WAIT=9 Command timed out at c:\test\junk9.pl line 11. Got: '12345678' c:\test>junk9 -WAIT=10 Got: '12345678910' c:\test>junk9 -WAIT=11 Got: '12345678910'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."