my $pid1 = open(PIPE1, "myprog1|"); my $pid2 = open(PIPE2, "myprog2|"); while ($pid1 >= 0 || $pid2 >= 0) { my $pid = wait; if ($pid == $pid1) { print "myprog1 completed.\n"; $pid1 = -1; } elsif ($pid == $pid2) { print "myprog2 completed.\n"; $pid2 = -1; } } my $output1 = ; # this works (I see the output of "myprog1") my $output2 = ; # this works as well close PIPE1; # this fails! close PIPE2; # this fails as well!