perlre describes 2 experimental code features that can do this. Albeit in an ugly way:
@x = split /(?{ # This populates $^R pos() })some pattern(??{ # This returns an impossible pattern for long matches (pos()-$^R < 5) ? "" : "no\\bmatch" })/, $string;
Be warned though that this will backtrack and try to match again. For instance if you want to not match more than 4 ,'s, this will match 4 out of 6 commas, then will match 2 commas next time. So instead of preserving 6 commas you'll eat them up and get a blank field.

If this is not what you want then you have to do a lot more work. You have to make sure that it fails on all of the backtracks as well. This means that when you fail you need to remember the failure and fail every time you see that position. Like this:

# Be sure that these start clean! my %bad_r; my %bad_pos; @x = split /(?{ # This populates $^R pos() })some pattern(??{ # This returns an impossible pattern for long matches if (pos()-$^R < 3 and not $bad_r{$^R} and not $bad_pos{pos()} ) { ""; } else { $bad_r{$^R}++; $bad_pos{ pos() }++; "no\\bmatch" } })/, $string;
That is ugly! But it should work.

Update: Well it should if I had not missed the closing paren on the pos(). Thanks to ikegami for catching that.


In reply to Re: Can you do "conjunctive" (overlapping) conditions in a single regexp? by tilly
in thread Can you do "conjunctive" (overlapping) conditions in a single regexp? by puterboy

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.