in reply to reducing the number of lines

Why do you need to simplify the code? Reducing the number of lines is not easy, but refactoring the similar parts to subroutines is possible:
sub assign_max { my ($x, $y) = @_; $s[$b1] = max($x, $y); } sub compare { my ($ar, $idx, $subst) = @_; if ($ar->[$idx] == 0 && $subst > 0) { $ar->[$idx] = $subst; } } $h = $s[$b] == 0 ? 0 : $s[$b] - 1 unless $l == $k; $c = (0, 1, 2)[$l <=> $k]; if ($l < $k) { compare(\@s_rev, $d + 1, $k - 2); assign_max($k, $lt); $j++; } elsif ($l > $k) { compare(\@s, $b + 1, $l - 2); assign_max($l, $kt); $i++; } else { compare(\@s, $b + 1, $k - 2); assign_max($k, $lt); $h = 0; }
As you can see, assign_max uses @s and $b1 as globals.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ