use strict;
my $str = '888-426-6840 215-861-6239
SPAIN Toll-Free: 900-8-01334
Caller Paid: 9-1-7878580
ITN Number: (*8) 2650 6840
Sandy Phillips 845-433-6476
USA Toll-Free: 888-426-6840
USA Caller Paid: 215-861-6239
Blackberry One Click +1-888-426-6840x6014774#
Call-In#: 888-426-6840 or 215-861-6239
USA/Mexico Toll-Free: 888-426-6840
Hungary Toll-Free: 06-800-19-306
Canada Toll-Free: 888-426-6840
UK Toll-Free: 0800-368-0638/02030596451
USA Toll-Free: 888-426-6840
USA Caller Paid: 215-861-6239
United Kingdom Caller Paid 0-20-30596451
United Kingdom Toll-Free 0800-368-0638';
my $regex = qr/(?:\d([\-\. ])?){7,15}/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