sub setEnvironment() { if ( fileno OUT ) { unless ( open(STDOUT, ">&OUT") ) { print "Cannot redirectrestore STDOUT"; return 2; } unless ( open(STDERR, ">&ERR") ) { print "Cannot redirectrestore STDERR"; return 2; } } else { unless ( open(OUT, ">&STDOUT") ) { print "Cannot redirect STDOUT"; return 2; } unless ( open(ERR, ">&STDERR") ) { print "Cannot redirect STDERR"; return 2; } } unless ( open(STDOUT, "|tee -ai $g_LOGPATH/$g_LOGFILE") ) ... Why and how does this work? We simply want to temporarily restore the original STDOUT immediately before rewiring it into tee, so that tee inherits ittemporarily restore the original STDOUT immediately before rewiring it into tee, so that tee inherits it as its standard output and actually writes directly to the original STDOUT (e.g. your terminal) instead of writing (in the case of the forked children) through the parent's tee (which is where the child's STDOUT normally pointspointed to before this change, by virtue of inheriting from the paremnt process, and which is what injected those child lines into parent.log.) In
So in answer to one of your questions, whoever wrote the code to set OUT and ERR must have had exactly the above in mind. (I cannot help but wonder whether or not the difference in indentation in your original code is indicative of someone having removed, in the past, code similar to the one you have to add back now.)