in reply to redirecting STDOUT output to variable?

The following might be sufficient:
{ my $captured_stdout = ''; local *STDOUT; open(STDOUT, '>', \$captured_stdout) or die $!; ... }