my $old_fh = select NoPrint->new; ## deep inside some test somewhere... print "foo\n" or warn "print failed (1)"; select $old_fh; ## now printing is back to normal again: print "foo\n" or warn "print failed (2)";