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";
}
|