in reply to Redirecting stdout/stderr to pipe
Use select to poll for available data on each of your filehandles, adding to a variable to keep track of the amount of output they've produced.