in reply to if statement consolidation

Use "data driven" as described in this thread. Or use XS, a C switch statement is orders of magnitude smaller in memory than your code, especially if all these numbers fit in the range of a char. For a pure perl solution, to reduce opcodes (nextstates and sassigns), convert a
$j=$h+8; $p=1; $v=8;
to (one aassign op)
($j, $p, $v) = ($h+8, 1, 8);
or fatter but faster (no nextstates, but multiple sassign might be faster one aassign a profiler, I dont remember from last time I tried to optimize away nextstate ops)
($j = $h+8),($p = 1), ($v = 8);
note, I didn't B::Concise this post.