The easiest way to get the part of the data before the string was found is to capture all of it.

Another approach is the one [id://Trix606] suggested... but be careful with it (as perlvar says): it impose a penalty on every regular expression... which slows down each match. Which is a bad idea.

Yet another approach is mentioned in the perlretut pod.

Some comments on this code. (Maybe relevant, maybe not.)

First, posting the code you are actually using might proof to be easier... and will result in better help.
(I say this because you have a syntax error in your code... (a missing ; after the print statement). This makes me guess that you didn't post the actual code)

Second, What if @dependantFiles contains a regex charachters? Do you want them to be interpreted or not? If not then you should look at the quotemeta function and/or \Q and \E in one of the perlre PODS (perlreref might be a good starting place).

Speaking about the regex: there is no need for the regex to be global. So drop the /g.

Another good idea is to use a lexical loop variable... it will make your live easier...

Doing next; at the end of the loop is pretty useless... (but it might make more sense in your actual code... (as in, the next is in an if-statement, and there is some other code behind it))


In reply to Re: regex expression help by Animator
in thread regex expression help by JFarr

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.