use strict;
my $str = 'ATU99999999
BE0999999999
BG999999999
HR12345678901
CY99999999L
CZ12345678
DK99999999
EE123456789
FI99999999
FRXX999999999
DE999999999
EL123456789
HU12345678
IE1S23456L
IE1234567T
IE1234567TW
IE1234567FA
ESA12345678
ESZ1234567E
DE813992525';
my $regex = qr/(?xi)^( (DE)?[0-9]{9}|)$/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