use strict;
my $str = 'DE 1 DE
DE 2 DE
DE 3 DE
DE 4 DE
DE 5 DE
DE 6 DE
DE 7 DE
DE 8 DE
DE 9 DE
DE 10 DE
DE 11 DE
DE 12 DE
DE 13 DE
DE 14 DE
DE 15 DE
DE 16 DE
DE 17 DE
DE 18 DE
DE 19 DE
DE 20 DE
DE 21 DE
DE 22 DE
DE 23 DE
DE 24 DE
DE 25 DE
DE 26 DE
DE 27 DE
DE 28 DE
DE 29 DE
DE 30 DE
DE 31 DE
DE 32 DE
DE 0 DE
';
my $regex = qr/DE\s+(3[01]|[12]\d|[1-9])\s+DE/mp;
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