use strict; use warnings; ## set up data in memory my $tm=time; my $file= "FRED.DAT"; my $data; { open my $fh, '<', $file or die; local $/ = undef; $data = <$fh>; close $fh; } ## report load statistics my $str="XYZ"; my $lx=length($data); my $tmx=time-$tm; my $r=$lx/$tmx; print "File $file cached $lx bytes in $tmx seconds @ $r bs\n"; ## scan mega string for patterns and do stuff my $nextposn=0; my $offset=0; ## experiment with offset beyond 1949803025 ## $offset=2500000000; my $found=0; my $occ=0; while ($nextposn < $lx ) { $nextposn = index($data,$str, $offset); if($nextposn < 0) {goto NOMORE;} $found++; ## do stuff you need to do with the next characters ## ## $offset = $nextposn+1; ## report progress $occ++; if ($occ == 1000000) {print "$found so far $nextposn\n"; $occ=0;} } ## diagnostics NOMORE: print "Processed $found patterns, maximum position was $nextposn\n";