You seem to be parsing out sentences, and that's a tricky, natural language sort of thing to do, and perhaps not best done with regexen. If you can do it, the  \u \U \l \L "interpolation control" (as I think of them) operators or escape sequences may come in handy for the transformations you want (see Quote and Quote-like Operators in perlop — and don't forget  \Q \E too). You can avoid the  /e regex modifier. With a very naive definition of a sentence pattern:

c:\@Work\Perl>perl -wMstrict -le "my $s = 'perlmonks IS a gREat site. dO you tHiNk SO? I loVE it!'; print qq{'$s'}; ;; my $senterm = '.?!'; my $sentence = qr{ \b [[:alpha:]] [^\Q$senterm\E]* [\Q$senterm\E] }xm +s; ;; $s =~ s{ ($sentence) }{\u\L$1}xmsg; print qq{'$s'}; " 'perlmonks IS a gREat site. dO you tHiNk SO? I loVE it!' 'Perlmonks is a great site. Do you think so? I love it!'

An equivalent  /e substitution would be
    $s =~ s{ ($sentence) }{ ucfirst lc $1 }xmsge;
Is there any significant speed difference?


In reply to Re: regular expression search and replace by AnomalousMonk
in thread regular expression search and replace by heman

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.