if ($to_file) { open(my $out_fh, '>', ...) or die(...); select($out_fh); } ... print "blah\n";