use strict;
my $str = '################################### This is allowed ##########################
+49 15207930698
+49 15207955279
+49 1739341284
+49 1626589266
+49915175461907
+4915207930698
+491635556416
017687400179
015903900297
015175355164
015175354885
01771789427
+49 915175461907
+43 915175461907
+49159039012341
+43159039012341
+4915207829969
+4917697400179
+4915903904567
+4915902944599
+4915902944599
+4915903904567
+491739341284
+431739341284
+49 176 97 456 123
0176 79 123 17 9
0176 97 50 01 79
0176 79 123 179
0174 80123179
0049 915175461907
0043 915175461907
0049159039012341
0043159039012341
004915207829969
(+49) 17697123456
+(49) (1739) 34 12 84
+49 (1739) 34-12-84
############################################################################################
################################### This is NOT allowed ####################################
012345678901234
123w345345345345
0123456789101191919
### Too short
+49 15902
+49 1590123
+49 15903567
+49 177178796
+49 757130309
+4915902
+491590123
+4915903567
+49177178796
+49757130309
### Too long
+49 1590345985412
+491590345985412
### Not German and not Austrain format
+12127319863
+13322014056
+12126712234
+427532697710
+417868150810
+287533002875
';
my $regex = qr/.*(?:\+49|0049|\+\(49\)|\+43|0043|\+\(43\)).*/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