in reply to Substr warning

This is a little off topic, but I think it is of note anyway. You might want to consider changing your code so as not to use $', $', $` and $& are not set by perl unless you use them in your code. If you use any of these variables for one regex, perl must suplly them for all regexes (performace hit, memory hit). I don't see any reason that would stop you from modifying your regex so that the desired additional characters are returned in $1. This might help avoid the errors you are seeing, as well as boost the performance of your script.

May the Force be with you