title: Redirect stdout to a variable while requiring other script
body: <p>I'm trying to redirect STDOUT to a variable, which seems to work fine. However, when I'm requiring other script, its expected output is not stored in that variable. </p>
  
  <pre><code>my $var;
  
  #save STDOUT for future redirect
  open OLDOUT, '&gt;&amp;STDOUT';
  close STDOUT;
  
  # redirect STDOUT to $var 
  open STDOUT, '&gt;', \$var or die "Can't open STDOUT: $!";
  
  # run the script that I'm supposed to catch its output
  do("macro.pl");
  close STDOUT;
  
  # redirect STDOUT to its original FH
  open STDOUT, '&gt;&amp;OLDOUT' or die "Can't restore stdout: $!";
  close OLDOUT or die "Can't close OLDOUT: $!";
  
  # print the expected result from macro.pl
  print "$var";
  </code></pre>
  
  <p>The last line prints nothing, which is not the expected result (running macro.pl alone yields a non-empty output). </p>
  
  <p>Tried it also with require - same result.
  It is worth mentioning that macro.pl doesn't - in any way - changes the standard file descriptors. </p>
  
  <p>Thanks!</p>