The solution with a greedy match-all .* expression preceding your regex is good and fine (and it is what I would have suggested if no one else had proposed before), but please note that if your scalar is really huge, you will probably get the following warning:
Complex regular subexpression recursion limit (32766) exceeded at ...
indicating that, perhaps, the regex is not using the regex engine in the most optimal way. It probably does not matter so much if you do it only once or just a few times, and the warning can presumably be silenced out with a pragma such as no warnings qw/regexp/; (I haven't tested), but if you're doing that many many times, then you might want to find another solution, for example a somewhat subtler regex that would not backtrack so much, by making some additional assumptions on the content of your scalar before (or possibly after) the place you want to match.

In reply to Re: Regex to find the last matching set in a long scalar by Laurent_R
in thread Regex to find the last matching set in a long scalar by superwombat

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.