open HANDLE, "some_script |"; push @INPUT, *HANDLE; while (<@INPUT>) { if ($some_condition) { open HANDLE, "some_other_script |"; push @INPUT, *HANDLE; } do_something_with_input(); } #### use IO::Select; $select = IO::Select->new(); # repeat next line for all filehandles to poll $select->add(*FILEHANDLE); if (@ready = $select->can_read(0)) { # input waiting on the filehandles in @ready }