#!/usr/bin/perl use strict; use warnings; use feature 'say'; my $string = "This sting it's bothering to escape ' single characters"; $string =~s/(\W)/\\$1/g; say $string; __END__ $ perl test.pl This\ sting\ it\'s\ bothering\ to\ escape\ \'\ single\ characters