The thing is that if there is only one '\' character, then it should be doubled, but if there is two then not. Basicly if there is even amount then no change, and odd, then change the last. So direct test on last char doesn't really work.
But thanks for the term help. As all my perl (and most of my coding as well) is self-taught :).