In reply to Nero.

Thank you, Nero. I also tried several different versions and chose the most efficient one. I would love to see a faster implementation though. However, I realize that speed of execution depends on the distribution of repeated characters as well as the length of duplication streaks, so there might not be a universally "better" implementation as it is data-dependent.

As for "endfunc" vs. "endsub", I think you can use them interchangeably, but I prefer using "endfunc" for functions, and "endsub" for subroutines.