use IO::Select; my $s = new IO::Select(); my $pid = open PH, "arbitrary command|" or die "arbitrary command: $!"; $s->add( \*PH ); my @ready = $s->can_read( 3000 ); if (@ready == 0) { # nothing to read, kill the child and close the pipe kill( $pid); close PH; } else { while () { # do something with the output } }