$_ = "one\ttwo\nthree four five\r"; s/(\t)|(\n)|(\r)|(\f)/ ($1 && '\t' || '') . ($2 && '\n' || '') . ($3 && '\r' || '') . ($4 && '\f' || '') /ge;