A quick trip through Deparse shows that perl changes the substitution to this:

$template =~ s[ \[% \s+ IF \s+ (\w+) \s+ %\] # $1 var (.*?) # $2 then \[% \s+ END \s+ %\] ][do { my($a, $b, $c) = ($1, $2, ''); if ($b =~ /[% \s+ ELSE \s+ %]/gsx) { #==============^ ^ backslashes removed! my(@c) = split(/[%\s+ELSE\s+%]/s, $b, 2); #=======================^ ^ backslashes removed! warn 'c(', join('|', @c), ')' if DEBUG; $b = $c[0]; $c = $c[1]; } warn "a($a) b($b) c($c)\n----\n" if DEBUG; defined $$v{$a} && $$v{$a} ? $b : $c; };]egsx;

Note that the backslashes were removed from the regexes! Time for a bug report?

On a hunch, I changed the second set of delimeters from square brackets to curly brackets, the output is as you expected originally.

Update: perl 5.8.0 (ActiveState build 806) on Win2K

Update: The more I think about it, I don't consider this a bug. If you use double-quotes to delimit a string ("\"Hello\""), backwhacking the delimiter results in the double quote as part of the string. The same should hold for square brackets as a delimiter.


In reply to Re: matching / splitting within a substitution by jsprat
in thread matching / splitting within a substitution by PodMaster

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.