title: perl seek and remove at varying offsets in binmode
body: <p>This is my script I am writing.</p>
  
  <pre><code>#usr/bin/perl
  use warnings;
  
  
  open(my $infile, '&lt;', "./file1.bin") or die "Cannot open file1.bin: $!";
  binmode($infile);
  open(my $outfile, '&gt;', "./extracted data without 00's.bin") or die "Cannot create extracted data without 00's.bin: $!";
  binmode($outfile);
  
  local $/; $infile = &lt;STDIN&gt;;
     print substr($infile, 0, 0x840, '');
     $infile =~ s/\0{16}//;
     print $outfile;
  </code></pre>
  
  <p>I'm loading a binary file in perl.
  I have been able to seek and patch at certain offsets, but what I would like to do is, now be able to find any instance of "<code>00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</code>" (16 bytes?) and remove it from the file, but no less than 16 bytes. Anything less than that I would want to leave. In some of the files the offset where the 00's start will be at different offsets, but if I am thinking correctly, if I can just search for <code>00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</code> and remove any instance of it, then it won't matter what offset the 00's are at. I would extract the data first from specific offsets, then search the file and prune 00's from it. I can already extract the specific offsets I need, I just need to open the extracted file and shave off <code>00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</code></p>
  
  <pre><code>EF 39 77 5B 14 9D E9 1E 94 A9 97 F2 6D E3 68 05
  6F 7B 77 BB C4 99 67 B5 C9 71 12 30 9D ED 31 B6 
  AB 1F 81 66 E1 DD 29 4E 71 8D 54 F5 6C C8 86 0D 
  5B 72 AF A8 1F 26 DD 05 AF 78 13 EF A5 E0 76 BB 
  8A 59 9B 20 C5 58 95 7C E0 DB 44 6A EC 7E D0 10 
  09 42 B1 12 65 80 B3 EC 58 1A 2F 92 B9 32 D9 07 
  96 DE 32 51 4B 5F 3B 50 9A D1 09 37 F4 6D 7C 01 
  01 4A A4 24 04 DC 83 08 17 CB 34 2C E5 87 26 C1 
  35 38 F4 C4 E4 78 FE FC A2 BE 99 48 C9 CA 69 90 
  33 87 09 A8 27 BA 91 FC 4B 77 FA AB F5 1E 4E C0        I want to leave everything from
  F2 78 6E 31 7D 16 3B 53 04 8A C1 A8 4B 70 39 22 &lt;----- here up
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 &lt;----- I want to prune everything
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00        from here on
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00&lt;---- this IS the end of the file, and
                                                       just need to prune these few rows
                                                       of 00's
  </code></pre>
  
  <p>Say that "<code>F2 78 6E</code>" from the example above, is at offset <code>0x45000</code> <strong>BUT</strong> in another file the 00 00's will start at a different offset, how could I code it so the <code>00 00's</code> would get pruned. In any file that I am opening?
  If I need to be more specific, just ask.
  Seems like I would peekk so far into the file until I hit a long 00 00 string, then prune any remaining lines. Does that make sense at all?
  All I want to do is search the file for any instances of <code>00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</code> and delete/prune/truncate it. I want to save everything but the 00's</p>
  
  <p><strong>EDIT #2</strong>
  this did it:</p>
  
  <pre><code>open($infile, '&lt;', './file1') or die "cannot open file1: $!";
  binmode $infile;
  open($outfile, '&gt;', './file2') or die "cannot open file2: $!";
  binmode $outfile;
  
  local $/; $file = &lt;$infile&gt;;
  $file =~ s/\0{16}//g;
  print $outfile $file;
  
  
  close ($infile);
  close ($outfile);
  </code></pre>
  
  <p><strong>Thank you <code>ikegami</code> for all your help and patience :)</strong></p>