my $data=''; $data.=pack('C', int rand(256)) for(0..$length/8); #... vectr => sub { my ($last,@cache)=(0); for ( my $i = $start; $i <= $end; $i++ ) { my $v = vec($data,$i,1); if ($v xor $last // !$v) { push @cache, $v ? 1 : -1 } else { $cache[-1] += $v } $last = $v; } },