title: Perl: Unget to <>
body: <p>I would like to read 100 KB from &lt;>, do some testing on that and then put the 100 KB back, so they will be read by &lt;> later.</p>
  
  <p>In metacode:</p>
  
  <pre><code>$data100kb = read(&lt;&gt;,100000);
  testing($data100kb);
  unget(&lt;&gt;,$data100kb);
  while(&lt;&gt;) {
    do stuff;
  }
  </code></pre>
  
  <p>I do not know in advance if &lt;> will supply me an actual file, a pipe or a concatenation of actual files. So it should work with:</p>
  
  <pre><code>cat bigfile_a bigfile_b | perl my_program
  </code></pre>
  
  <p>Assume bigfiles are 1000*RAM size, so copying the input is prohibitively expensive.</p>
  
  <p>It is acceptable if I can only read from STDIN. </p>
  
  <p><strong>Background</strong></p>
  
  <p>The first 100kb tells me how to parse the full input, but the parser needs this input as well.</p>