in reply to Binary File Manipulation across Byte boundaries

Expanding on zudes theme. Provided you have say 10 times more RAM that the file size then this is a very simple approach that should be quite speedy as well. If memory is an issue then you would need to implment a sliding buffer.

my $data = 'abacad'; # slurp in whole file into scalar my $pattern = 'a'; my $ds = unpack "B*", $data; my $ps = unpack "B*", $pattern; my $proof = '-' x length($ds); my $x = 0; while ( 1 ) { $x = index($ds,$ps,$x); last if $x == -1; print "Match at bit offset $x\n"; # modify proof string to show match, could extract surrounding # bits just as easily using our $x offset and substr() on $ds substr( $proof, $x, length($ps), $ps ); $x++; # move offset pointer to next bit to avoid endless loop } print " Original: $ds Matches: $proof\n"; __DATA__ Match at bit offset 0 Match at bit offset 16 Match at bit offset 32 Original: 011000010110001001100001011000110110000101100100 Matches: 01100001--------01100001--------01100001--------

cheers

tachyon