use strict; use warnings; s/(\\(?:\W|\w{1,3}))/qq("$1")/gee, print for ; __DATA__ this is a string\t$foowith some text\r\n this is a string\010with some\x09text\r\n