use strict;
my $str = '+389 70 123 456
389-71-234-567
389-071-234-567
389-0071-234-567
00389.72.345.678
+389/73/456/789
389 75 123456
389 76-234-567
+38970123456
38971234567
0038972345678
+38973456789
38975123456
38976234567
38980123456
+38982123456
+389 70 123-456
+389 70 323-456
389(71)234.567
389(071)234.567
00389/723-456-78
+389 (73) 456.789
389 75 123/456
389 76-234.567
389.80.123.456
389.(080).123.456
+389-82-123-456
00389 (81) 234-56
389/931-234-56
+3899512-3456
00389(95)12.345
389/10-123-456
389 11-123/456
+389 12.123-456';
my $regex = qr/^(0{0,2}\+?389[\s./-]?)(\(?[0]?[7-7][0-9]\)?[\s./-]?)([2-9]\d{2}[\s./-]?\d{3})$/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