use strict;
my $str = 'A0
B11
CC2
DD3D
EE44
F5 5FF
G77 7GG
HH8 8HH
II9 I 9II
JJ00 0JJ
00
0A
AA
111
1B1
11B
C1C
1CC
CCC
3333
D333
3D33
33D3
333D
E4E4
E44E
4EE4
4E4E
44EE
DDD3
D3DD
3DDD
DDDD
';
my $regex = qr/^[a-z](\d\d?|[a-z]\d[a-z\d]?|[a-z]?\d?\d \d[a-z]{2}|[a-z]\d [a-z] \d[a-z]{2})$/imp;
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