#! 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'";