on the other hand Regexp::Debugger - amazing tool, thank you. It shows what the problem and it is what I suspected, but I have no idea why is it matching this way and I have no idea how to fix this. As you see in my code I have a s/ replace and after first replace the matching is weird