title: Perl: Print on the "display" and also into a file
body: <p>Is there any way to print both onto the "display" and also into a file at the same time without repeating the print "string" code?</p>
  
  <p>What I want to do:</p>
  
  <pre><code>if ($ofile) {
     open (FILE, '&gt;&gt;', "file");
     print "Hello" #some code#; #prints on the display and into the file
  }
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>if ($ofile) { open (FILE, '&gt;&gt;', "file"); }
  print "Hello";
  if ($ofile) { print FILE "Hello"; }
  </code></pre>
  
  <p>Tried googling but all I found was either or, not both features together.</p>
  
  <p>Edit to add questions:</p>
  
  <p>Then use IO::Tee to create a new tee'd handle, and then select $tee so that print uses it by default. – Eric Strom</p>
  
  <p>@EricStrom What do you mean by create a new tee'd handle? Do you mean this <code>Local::TeeOutput</code>? search.cpan.org/~mschilli/Log-Log4perl-1.34/lib/Log/Log4perl.pm</p>
  
  <p>@EricStrom Do you have an example?</p>
  
  <p>@EricStrom Local::TeeOutput is not available in the default library for Strawberry Perl. Is there any alternative that's inside the default library?</p>