Guessing the answers to my questions above, this works for your somewhat limited sample:

#! perl -slw use feature qw[ state ]; use strict; sub findEm { state $protected; my( $fh, $blkSize, $chr, $chrCount ) = @_; my @returns; local $/ = \$blkSize; while( <$fh> ) { my( @matches, @protected ); ## If we had a protected zone that spans the block boundary ## start with the residual push @protected, $protected if defined $protected; ## Look for preliminary matches push @matches, $-[0] while m[(${chr}{$chrCount,})]g; ## skip ahead if there are none. next unless @matches; ## look for protected zones push @protected, [ $-[0], ord( $1 ) ] while m[\x74\x75\x76\x77 +(.)]g; ## If there are some, and the last spans off the end of this b +lock ## record the residual for the next block if( @protected and $protected[ -1 ][ 0 ] + $protected[ -1 ][ 1 ] > $blkSize ) { $protected = [ 0, ( $protected[ -1 ][ 0 ] + $protected[ -1 ][ 1 ] ) % $b +lkSize ]; } else { $protected = undef; } ## Destructively iterate the protected zones while( @protected ) { my( $start, $len ) = @{ pop @protected }; ## comparing them against each match (backward) for my $iMatch ( reverse 0 .. $#matches ) { my $match = $matches[ $iMatch ]; ## if this match precedes the start of ## the current protected zone, next zone last if $match < $start; ## If this match is beyond the end of the current zone +, ## next match next if $match > ( $start + $len ); ## The two overlap so discard the match splice @matches, $iMatch, 1; } } ## Calculate the file offset of the current block my $fOffset = ( $. -1 ) * $blkSize; ## In a non list context unless( wantarray ) { ## undef unless we've at least one match return unless @matches; ## or the file offset of the first if we have one or more return $fOffset + $matches[ 0 ]; } ## Map the match block offsets to file offsets and remember th +em push @returns, map $fOffset + $_, @matches; } ## return them return @returns; } my $fileData = pack 'H*', join'',split ' ', do{ local $/; <DATA> }; open RAM, '<', \$fileData; print 'Scalar context: ', scalar findEm( \*RAM, 0x40, chr(0), 8 ); close RAM; open RAM, '<', \$fileData; print 'List context ', join ', ', findEm( \*RAM, 0x40, chr(0), 8 ); __DATA__ 09 43 4A 00 00 00 00 00 00 00 00 00 00 00 FC B0 DD 12 46 33 73 7A 8B 01 00 00 00 00 00 00 98 40 34 3F 79 6D DC 2A 2B 35 FF 90 FA 60 66 58 5A 21 40 06 88 F2 11 EE 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 88 CC 02 A0 74 75 76 77 09 00 00 00 00 00 00 00 00 00 AA

Outputs:

C:\test>891765 Scalar context: 3 List context 3, 55, 64

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Finding large blocks consisting of a single character (but within certain parameters...) by BrowserUk
in thread Finding large blocks consisting of a single character (but within certain parameters...) by TheMartianGeek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.