Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

- $stream1 is the STDOUT of a child process and $stream2 is the STDERR of the same child process
- $stream1 is one child process and $stream2 is another child process

Is there a possiblility in perl to monitor two or more streams at the same time?

So we loop as long as anything pops-up in any of the streams and we take whatever comes first either in $stream1 or $stream2.

Something like

while (my $line = <$stream1 or $stream2> ) {  
    #do something with the $line


share|improve this question
up vote 3 down vote accepted

Sure there is - it's Perl, after all - just not with quite such an elegant syntax.

Monitoring several streams boils down to judicious use of the select syscall, and in Perl that means using the four-argument version of select, which wraps this syscall. Many people find this a bit too cumbersome and low-level, so of course there is a module which further wraps the pattern for your convenience.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.