close STDOUT; open STDOUT, '>', \my $buffer or die $!; print ....; # This will append the output to $buffer