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; }