Another strategy would be to simply do the subtitution on a substring that leaves out the first and last char:
substr($t, 1, -1) =~ s/"/""/g;
This however seems to be slower, according to a quick benchmark I've run (zwa = 'zero-width assertion', sub = 'substr'):
Benchmark: timing 1048576 iterations of sub, zwa... sub: 16 wallclock secs (15.07 usr + 0.00 sys = 15.07 CPU) @ 69 +580.36/s zwa: 13 wallclock secs (12.58 usr + 0.00 sys = 12.58 CPU) @ 83 +352.62/s Rate sub zwa sub 69580/s -- -17% zwa 83353/s 20% --
But it is perhaps easier to understand (which would make it a better choice if the speed difference isn't relevant)

•Update: ran the benchmark again, this time without other processes eating up wallclock secs; to avoid confusion

•Update: I'm enclosing my (fairly pointless) benchmark stuff in readmore-tags to avoid cluttering the thread


In reply to Re: Regex matching on anywhere but the beginning or end of a line by xmath
in thread Regex matching on anywhere but the beginning or end of a line by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.