if ($v ne $last || $v eq '0') { push @cache, $v eq '1' ? 1 : -1 } elsif($v eq '1') { $cache[-1] ++ }