in reply to Multiple outputs in a CGI script

One short answer, wrap these two kinds of output in subroutines. Long answer:
sub output { my $text = shift; print STDOUT $text; } sub output_logged { my $text = shift; local *STDOUT; open(STDOUT, "| tee $filename") || die "Can't open pipe: $!"; print STDOUT $text; close STDOUT; }
Other options include returning a filehandle from a subroutine and printing to that wherever you go. Remember, you can return a typeglob and capture it in a scalar.