#!/usr/local/bin/perl -w use strict; open IN, '< :raw', $ARGV[ 0 ] or die "$ARGV[ 0 ] : $!"; open OUT, '> :raw', $ARGV[ 1 ] or die "$ARGV[ 1 ] : $!"; my $a = ''; my $b = ''; my $buffer; sysread IN, $buffer, 5800, 5800; do{ ## Move the second half of the buffer to the front. $buffer = substr( $buffer, 5800 ); ## and overwrite it with a new chunk sysread IN, $buffer, 5800, length( $buffer ); ## Apply the regex $buffer =~ s|$b(.*?)$a||g; print $buffer; ## Write out the first half of the buffer syswrite OUT, $buffer, 5800; } until eof IN; close IN; close OUT;