in reply to Strange substr Problem

Your code looks just fine, doesn't matter whether it looks perlish or not.

I suggest you to study the actually content of your string, by using something like ord().

I am not saying garbage characters will make your code go wrong, but it would confuse you, as an observer, in various ways.