use strict;
my $str = 'NPO1234567
NPO12345678
NPO123456
NPO123456789
npo1234567
npo12345678
npo123456
npo123456789
PRO1234567
PRO12345678
PRO123456
PRO123456789
pro1234567
pro12345678
pro123456
pro123456789
PCR1234567
PCR12345678
PCR123456
PCR123456789
pcr1234567
pcr12345678
pcr123456
pcr123456789
REQ1234567
REQ12345678
REQ123456
REQ123456789
req1234567
req12345678
req123456
req123456789
81234567
812345678
8123456
8123456789
';
my $regex = qr/(?i)^(?:NPO|PRO|PCR|REQ|8)+(\d{7,8})(?!(\d))/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