Here&#39;s a horrible possibility using a code assertion:<br><br><br>my $end = 0;<br>my $st = 0<br># no comments to discourage usage <br><br>$code =~ s/ ^(?: \s:(?{$st++;}) | (?{ $end++ if $st }) )  /<br>            $st == 1 ? &quot;&lt;code&gt;&quot; : ($end==1 ? &quot;&lt;\\code&gt;&quot; : &quot;&quot;)<br>
          /gmex;  <br><br>which produces:<br><br>foo bar<br>baz<br><br>&lt;code&gt;    sub hello {<br>        say &quot;Hello World!&quot;;<br>    }<br>&lt;\code&gt;asdf<br>snap<br>crackle<br>pop<br><br>--- <br>Charles DeRykus<br>
<br><br><div class="gmail_quote">On Thu, Jun 25, 2009 at 12:00 AM, Ryan Corder <span dir="ltr">&lt;<a href="mailto:ryanc@greengrey.org">ryanc@greengrey.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Wed, Jun 24, 2009 at 07:48:22PM -0700, Charles DeRykus wrote:<br>
| Er, wouldn&#39;t this work even with the added qualification:<br>
|<br>
| $code = &quot;[code]${code}[\\code]&quot;;<br>
| $code =~ s/^ ://gm;<br>
<br>
</div>No, that&#39;s the same problem.  I can&#39;t just wrap the entirety of $code<br>
inside [code] tags.  Using your example and if $code contained the following:<br>
<br>
my $code=&lt;&lt;__CODE__;<br>
foo bar<br>
baz<br>
<div class="im"><br>
 :    sub hello {<br>
 :        say &quot;Hello World!&quot;;<br>
 :    }<br>
</div>asdf<br>
snap<br>
crackle<br>
pop<br>
__CODE__<br>
<br>
The output would like like this:<br>
<br>
    [code]foo bar<br>
    baz<br>
<div class="im"><br>
        sub hello {<br>
            say &quot;Hello World!&quot;;<br>
        }<br>
</div>    asdf<br>
    snap crackle<br>
    pop<br>
    [/code]<br>
<br>
which doesn&#39;t work for me.  I need to insert the [code] tags on either<br>
side of the substitution, inline with any content that may already be there.<br>
<div><div></div><div class="h5"><br>
<br>
--<br>
Ryan Corder                  ||     () ASCII ribbon campaign<br>
&lt;ryanc at <a href="http://greengrey.org" target="_blank">greengrey.org</a>&gt;     ||     /\  against HTML email<br>
<a href="http://pgp.mit.edu:11371/pks/lookup?op=get&amp;search=0x1CB59D69" target="_blank">http://pgp.mit.edu:11371/pks/lookup?op=get&amp;search=0x1CB59D69</a><br>
</div></div></blockquote></div><br>