in reply to subroutine return ternary output

When in doubt (and many other times also) use parentheses: they're there to keep your brains from dribbling sideways. ;) What does this do for you:
  return ( (0 == system($KSH_SCRIPT)) ? 1 : 2 );