$h = start /@cmd, /$in ,/$out; $in .= "some command"; pump $h until $out=~/some desired string/i;