$str = '"the "quick" brown "fox" jumps o""er "the" lazy "dog""'; substr($str,1,-1) =~ s/"/""/g; print $str; "the ""quick"" brown ""fox"" jumps o""""er ""the"" lazy ""dog"""