my $thread = async { my $tid = threads->tid(); my ( $out, $in ); chdir $wd or die "Can't cd to $wd: $!\n"; my $pid = open2( $out, $in, $cmd ); # die "$!\n"; print $in "$_\n" foreach (@input); close $in or warn "close of input: $! $?\n"; my $err = 0; while (<$out>) { chomp; $err = 1 if (/^thread failed/); $Q->enqueue("$tid:$uut:$test:$_"); last if ($err); } kill( 2, $pid ) if $err; close $out; $Q->enqueue("$tid:$uut:$test:ENDEND"); waitpid ($pid, 0); }; $thread->detach();