I don't have the time right now to go over almost nine hundred lines of C code to extract its functionality, but here's a version of your OPed Perl code that may perhaps serve as a starting point for what you want:
c:\@Work\Perl\monks>perl -wMstrict -le
"my $long = 'xxxxxxAAAAAxxxxxx';
my $short = 'AAxAA';
;;
my $len = length $short;
for my $offset (0 .. length($long) - $len) {
my $m = ($short ^ substr $long, $offset, $len) =~ tr{\0}{\0};
print qq{matched $m at offset $offset};
}
"
matched 1 at offset 0
matched 1 at offset 1
matched 2 at offset 2
matched 3 at offset 3
matched 2 at offset 4
matched 3 at offset 5
matched 4 at offset 6
matched 3 at offset 7
matched 2 at offset 8
matched 3 at offset 9
matched 2 at offset 10
matched 1 at offset 11
matched 1 at offset 12
Update: Pay close attention to the advice of BrowserUk; big-data processing is his bread and butter.
Give a man a fish: <%-(-(-(-<