$|++; open2(READ,WRITE,program); for (1..6000) { print WRITE $cmd; while () { if (/blah/) { do something; } else { do another thing; } } }