# warning, not tested my $out_fh; if ( $debug_flag ) { open FILE, ">debug.out" or die $!; $out_fh = *FILE; } else { $out_fh = *STDOUT; } # and then always do: print $out_fh $output; # it will go to the right place.