use InstallerHandleTie; select STDERR; $| = 1; # make unbuffered select STDOUT; $| = 1; # make unbuffered my $gfh = *STDOUT; my $geh = *STDERR; for (1, 2) { local *STDOUT; local *STDERR; my $outfile = "globlog_$_.txt"; open LOGFILE, ">$outfile"; tie *STDOUT, 'InstallerHandleTie', *LOGFILE, $gfh; tie *STDERR, 'InstallerHandleTie', *LOGFILE, $geh; print "STDOUT in $outfile\n"; warn "STDERR in $outfile\n"; untie *STDOUT; untie *STDERR; close LOGFILE; } print "outside of tie loop, I should not be in a log file\n"; warn "outside warning - not in log\n";