tie *LOCALFH, 'IO::Scalar', \$scalar; my $old_fh = select(LOCALFH); ...code that generates STDOUT... select $old_fh;