------------------ sub Pooled_function { my($id,$parentfh) = @_; print $parentfh "start\n"; close(STDOUT); close(STDERR); while (1) { chomp(my $pclass = <$parentfh>); my $file = "$build_logs_dir/$pclass.log"; open(STDOUT, "> $file") or die "Can't redirect stdout: to $file "; open(STDERR, ">&STDOUT"); # ----------- Do the stuff ------ close(STDOUT) or die "Can't close STDOUT: $!"; close(STDERR) or die "Can't close STDERR: $!"; print $parentfh "$id $pclass $result\n"; } close($parentfh); }