# non-blocking pipe using O_NONBLOCK file flag, unsafe(?) ... open $in, '-|', $command or die $!; # modified by bliako to set the filehandle to non-block IO use Fcntl; # EDIT: commented below is not supported and outputs warning about ORing non-numerical flags #my $flags = ""; #fcntl($in, F_GETFL, $flags) or die "failed to get flags, $!"; # use this instead: my $flags = fcntl($in, F_GETFL, 0); # reporting weird flags (linux)! print "FLAGS: '$flags'\n"; $flags |= O_NONBLOCK; fcntl($in, F_SETFL, $flags) or die "Couldn't set file flags: $!\n"; ... # and now read is non-block, # undef will be returned if no output ready read $in, my $buff, 100; if ($buff && length $buff) { # check if undef ... } ...