#!/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 $buffer; sysread IN, $buffer, 384, 384; do{ ## Move the second half of the buffer to the front. $buffer = substr( $buffer, 384 ); ## and overwrite it with a new chunk sysread IN, $buffer, 384, length( $buffer ); ## Apply the regex $buffer =~ s[ \xF4 . ## The marker byte plus friend ( .{190} ) ## 1520 bits to retain \xF4 . ## Second marker + friend ( .{58} ) ## 464 bits to retain .{132} ## 1056 bits to discard ][$1$2]xg; ## Write out the first half of the buffer syswrite OUT, $buffer, 384; } until eof IN; close IN; close OUT;