use strict;
my $str = ' [0] => sth!Man!Tree!null
[1] => sth!Maning!AppTree!null
[2] => sth!Man!Lake!null
[3] => sth!Man!Tree!null
[4] => sth!Man!AppTree!null
[5] => sth!Maning!AppTree!null
[6] => sth!Man!Tree!null
[7] => sth!Maning!AppTree!null
[8] => sth!Maning!AppTree!null
[9] => sth!Man!Tree!null
[10] => sth!Man!Tree!null
[11] => sth!Man!Tree!null
[12] => sth!Man!Tree!null
[12] => sth!Man!Lake!null
[13] => sth!Maning!Tree!null';
my $regex = qr/(?i)\b(?:Lake|Tree)\b.*\bMan\b|\bMan\b.*\b(?:Tree|Lake)\b/p;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html