use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); my $pid = open my $fh, '-|', 'sleep 3; echo aaaa' // die $!; my $flags = fcntl($fh, F_GETFL, 0) or die "failed to get flags, $!"; fcntl($fh, F_SETFL, $flags | O_NONBLOCK) or die "Couldn't set file flags: $!\n"; my $output = <$fh>; if( defined $output ){ print "got output: '$output'\n" } else { print "no output right now.\n" } print "now waiting to end ...\n"; #waitpid $pid, 0; close($fh); #kill 'TERM', $pid; print "end.\n";