title: How can I print to a variable instead of a file, in Perl?
body: <p>How can I print to a variable with Perl?</p>
  
  <p>I've been working on a program for a while which logs its <strong>iterative</strong> progress in a highly verbose fashion...</p>
  
  <pre><code>print $loghandle $some_message;
  </code></pre>
  
  <p>However, I'd like to also selectively print some of the messages to a different file. Naturally, I could sprinkle the code with...</p>
  
  <pre><code>print $loghandle $some_message
  print $otherloghandle $some_message
  </code></pre>
  
  <p>Or rewrite the whole business into a function. Blah.</p>
  
  <p>What I want to do is do some magic when I open the $loghandle so that when I'm <code>print</code>'ing, I'm actually just doing a <code>sprintf</code>ish operation against a variable(call it <code>$current_iteration</code>), so that when I get down to a decision point I can do something like this...</p>
  
  <pre><code>print $real_log_file $current_iteration;
  print $other_real_log_file $current_iteration if($condition);
  </code></pre>
  
  <p>I'm fairly sure I've seen something like this somewhere, but I have no idea where it is or where to look.</p>
  
  <p>edit: File::Tee solves this problem to some extent on *nix, but I run on Windows.</p>