my $pid = open CMD, '-|', $command or die $!; my $timeout = time() + 10; ## 10 seconds should be enough my $output = ''; while( ) { $output .= $_; last if $sharedFlag == ABORT; kill 9, $Pid, last if time() > $timeout; } close CMD; return $output;