use IO::Scalar; my $s; tie *STDOUT, 'IO::Scalar', \$s; print "line 1\nline 2\n", "line 3\n"; warn "String is now: $s\n"