I can't say I recommend this, but a sort of minimal change would be:

my $patternreadfromfile = q{<h1 tag="@{[substr "$2",1,-1]}">@{[substr "$1",1,-1]}</h1>};

It is probably more comprehensible to do something like this:

my $patternreadfromfile= q{do_what_i_want( $1, $2 )}; sub do_what_i_want { my ($one, $two) = @_; for ( $one, $two ) { s/\A.(.*).\z/$1/; } return qq{<h1 tag="$one">$two</h1>}; } my $outpattern = $patternreadfromfile;

Of course, you'll want to replace my silly names with your own silly names. If you don't want your namespace polluted with this sub, you could make it an anonymous sub in a lexical that will go away when you're done with it. In that case, it looks like this:

my $doit = sub { my ($one, $two) = @_; for ( $one, $two ) { s/\A.(.*).\z/$1/; } return qq{<h1 tag="$one">$two</h1>}; }; my $patternreadfromfile= q{$doit->( $1, $2 )};

In reply to Re: Regexp::Common balanced curlies substitution by kyle
in thread Regexp::Common balanced curlies substitution by iaw4

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.