$x = $bit ? $val : -$val; if ($bit xor $last_bit) { push @returned, $x } else { $returned[-1] += $x }