What I don't understand: The line in @arr has nothing in common with what you are printing. Where do you find the 'enable' string? Your problem description is very inconsistent

First of all you need a loop, you can't use a regex on an array. This can be done with an implicit loop like this:

@results= map(/^(lean : sigma)/,@arr); print "First content=> $_\n" for @results;

or explicit with:

foreach (@arr) { if (/^(lean : sigma)/) { print "First content=> $1\n"; } }

The regex will return whatever is inbetween the '()', if this is not a constant expression, substitute it with .* and it will get you anything till the end of line

Note this will print 'First content' for every match. If you want to have 'first', 'second', 'third'... you need to list those strings to perl since perl doesn't know about natural languages like english. So you would need something like this

@numberlist=('First','Second','Third','Fourth','Fifth'); #and so on as + high as the maximal number of matches you expect @results= map(/^(lean : sigma)/,@arr); $i=0; foreach (@results) { print $numberlist[$i++]," content=> $_\n"; }

In reply to Re^2: match array content of first and second match by jethro
in thread match array content of first and second match 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.