in reply to It's friday, I can't think.

There are several ways. You can play with select() as per chromatic's or plaid's posts. But if you have control over the subroutines you are better off printing directly to the filehandle when that's what you want to do. I also wanted to point out that plaid preserved the old filehandle, but <sigh> he didn't check for success opening the filehandle. Having just run into an issue with this, I'll also suggest localizing the filehandle to the subroutine. So my suggestion:
{ my $i = 1; # Function static var... ooooh. sub Whatever { my $select = (defined $_[0]) ? $_[0] : 0; my $old_fh; local *FH; open FH, ">>$file" or die "Failed to open $file, $!"; if( $select ) { $old_fh = select FH }; print FH "$i This will go to $file\n"; print "$i This will go to $file if \$select($select) is true.\n"; if( $select ) { select $old_fh } close FH or die "Failed to close $file, $!"; $i++; } } Whatever(0); Whatever(1); # Now the second print goes to FH.
I did some extra stuff there to make it more clear. The $i gets incremented with each call so you can differentiate the print outs. My first version of this post had the select before I opened the filehandle. I don't recommend that as any print between the select and the open would bomb. So I fixed my example.