in reply to Re^2: OT: Perl and Javascript - escaping newlines
in thread OT: Perl and Javascript - escaping newlines

In that case,
my $string = ... from db ...; my $jscode = $string; $jscode =~ s/(\W)/ sprintf('\\0%o', ord($1)) /ge; $jscode = qq{"$jscode"};
would also work.