title: Perl: Pass open file handle to a program reading STDIN
body: <p>I read a few lines from STDIN. How can I pass the remaining of STDIN to a command that reads from standard input (e.g. <code>md5sum</code> or <code>wc</code>)?</p>
  
  <p>I could do a:</p>
  
  <pre><code>read_a_few_lines_from_diamond_operator();
  open (C, "|cmd");
  while(&lt;&gt;) { print C }
  close C;
  cleanup_after_C();
  </code></pre>
  
  <p>but for efficency reasons I would like not to touch the input, but instead pass the filehandle of STDIN. Sort of like:</p>
  
  <pre><code>seq 10 | (read A; wc)
  </code></pre>
  
  <p>where <code>read</code> reads as much as it likes before passing the rest on to <code>wc</code>. I cannot use this solution, though, as I need to start the command from inside my perl program and I need to do work after <code>cmd</code> completes.</p>
  
  <hr>
  
  <p>I read a few lines from the file 'foo'. How can I pass the remaining to a command that reads from standard input (e.g. <code>md5sum</code> or <code>wc</code>)?</p>
  
  <p>I could do a:</p>
  
  <pre><code>open (F, "&lt;foo");
  read_a_few_lines_from_F();
  open (C, "|cmd");
  while(&lt;F&gt;) { print C }
  close C;
  cleanup_after_C();
  </code></pre>
  
  <p>but for efficency reasons I would like not to touch the input, but instead pass the rest of file 'foo'.</p>
  
  <hr>
  
  <p>I have a feeling it can to be done using trickery like <code>select</code>, <code>open(FOO,"&gt;&amp;STDOUT)</code>, <code>exec 6&lt;&amp;0</code>, <code>fork</code>, <code>pipe</code>.</p>