sub nasty2 { open my $fh, '>', 'output.txt' or die $!; select $fh; # everybody keep silent print "everybody keep silent"; # this shows up in } nasty2(); print "everybody keep silent"; # this shows up in the output file