use strict;
my $str = '123456789
987654321
987654322
987654323
98765432A12312
987654325
987654326
987654327
987654328
987654329
666218502
773218502
772218502
443218502
641218502
525.52.6969B
515-54-6976-A
555516316S
123.45.6789
987.65.4321
987.65.4322
987.65.4323
987.65.4324
987.65.4325
987.65.4326
987.65.4327
987.65.4328
987.65.4329
666.21.8502
773.21.8502
772.21.8502
772-21-8502
772218502
443.21.8502
641.21.8502';
my $regex = qr/\d{8}[A-Z]\d{5}/p;
if ( $str =~ /$regex/ ) {
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