( ( perl foo.pl | tee -a output.log ) 3>&1 1>&2 2>&3 3>&- | tee -a error.log ) 3>&1 1>&2 2>&3 3>&- #### my ($output_cache, $error_cache); *STDOUT = multiplex( \*STDOUT, $output_cache, "$log_dir/output.$0" ); *STDERR = multiplex( \*STDERR, $error_cache, "$log_dir/errors.$0" ); do $script or die "Could not open '$script': $!" exit; sub multiplex { my ($handle, $cache, $log) = @_; my $cache_handle = IO::String->new( \$cache ); my $log_handle = IO::File->new( $log, 'w' ) or die "Could not open log file '$log': $!"; my $tee = IO::Tee->new( $handle, $cache_handle, $log_handle ); return $tee; }