in reply to Appending print to a variable

Check out IO::Scalar. It can be used like this:

perl -MIO::Scalar -le 'my $s; $SH = IO::Scalar->new(\$s); print $SH "f +oo"; print $s'
Update: If you need to, you can even alias STDOUT to your IO::Scalar handle:
use IO::Scalar; my $s; my $SH = IO::Scalar->new(\$s); { local *STDOUT = $SH; print "foo\n"; } print $s;
That technique should enable you to avoid changing the current code.

Update 2: A better way to do that, rather than aliasing, is to use the tie interface provided by IO::Scalar. I probably should have recalled that, as I answered a similar question just over a month ago.

use IO::Scalar; $string = tie *STDOUT, 'IO::Scalar'; print "foo\n"; print STDERR '$string: ', $string; # Must use stderr as stdout is t +ied.

-sauoq
"My two cents aren't worth a dime.";