use strict; use warnings; while () { chomp; s/^['"]+|['"]+$//g; # Remove starting and ending quotes s/(['"{}])/\\$1/g; # Escape appropriate characters print "$_\n"; } __DATA__ "text with quotes" If it ain't broke, don't fix it. We all love {curly brackets}