As given, your example does not match anything. If you use re 'debug'; you will get a fairly cryptic trace of what the regular expression is doing:

$ perl -Mre=debug -E 'my @m='lkjkljkjlkhkjkfjkfkvklkv'=~/^\w*(kl(?1)\w*).*?(kv)/g; say for @m;'
Compiling REx "^\w*(kl(?1)\w*).*?(kv)"
Final program:
   1: SBOL /^/ (2)
   2: STAR (4)
   3:   POSIXU\w (0)
   4: OPEN1 (6)
   6:   EXACT <kl> (8)
   8:   GOSUB1-4:4 (11)
  11:   STAR (13)
  12:     POSIXU\w (0)
  13: CLOSE1 (15)
  15: MINMOD (16)
  16: STAR (18)
  17:   REG_ANY (0)
  18: OPEN2 (20)
  20:   EXACT <kv> (22)
  22: CLOSE2 (24)
  24: END (0)
floating "klkl" at 0..9223372036854775807 (checking floating) anchored(SBOL) minlen 6 
Matching REx "^\w*(kl(?1)\w*).*?(kv)" against "lkjkljkjlkhkjkfjkfkvklkv"
Intuit: trying to determine minimum start position...
  doing 'check' fbm scan, 0..22 gave -1
  Did not find floating substr "klkl"...
Match rejected by optimizer
Freeing REx: "^\w*(kl(?1)\w*).*?(kv)"

The trace says your match never got started because the string being matched does not contain 'klkl'. The first 'kl' is the literal one from your regular expression; the second is because of the recursion. I believe that even if the string contained 'klkl' there would be no match, because there is no way for the recursion to end; it would just look for 'klklkl', then 'klklklkl', and so on.

Can you say what you expect @m to contain in your example?

And can you provide an example where you match against the shortest possible string that you want to match successfully?


In reply to Re: To not capture recursive group while collecting certain matches by Anonymous Monk
in thread To not capture recursive group while collecting certain matches by Anonymous Monk

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.