in reply to weird error when using substring function

You used sub instead of substr

If that doesn't fix it, you'll need to try your code in a newer version of Perl. You're getting an internal error, so it's either been fixed in newer version, or needs to be fixed in newer versions. It won't get fixed in 5.6.x.

I can't get 5.6.1 to crash as you describe using the bad or the fixed code.