in reply to substr out of str error - but why?

Like the other honorable brothers already said, you didn't provide enough information for a decent analysis.

My guess is that your debugging only shows the initial length of the string, but not the current one.

If one of your previous replacements resulted in a shorter string because of a bug, you'll end up out of bounds.

see also hv's remark

> is length($opposite{$side1}) always 1.

I may add the same question for $side1 ...

On a side note: another critique to your code is that you are escaping too many elements in your regex, neither _ nor " are meta.

update

furthermore are you relying on input coordinates you are parsing, but without validating their correctness.

I can imagine various scenarios how this could fail.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery