use strict;
my $str = 'Valid:
022345677
032345677
042345677
062345677
082345677
092345677
0722345677
022345677
0742345677
0762345677
0742345677
0762345677
0772345677
0782345677
0792345677
0502345677
0512345677
0522345677
0532345677
0542345677
0552345677
0562345677
0582345677
0592345677
NotValid :
021345677
030345677
142345677
362345677
282345677
492345677
5722345677
622345677
7742345677
8762345677
9742345677
';
my $regex = qr/^(02|03|04|06|08|09|072|074|076|077|078|079|050|051|052|053|054|055|056|058|059)((?:(?![1,0]{1}))\d{7})$/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