use strict;
my $str = 'Task: Return only the residents of Spencerport, NY who have phone numbers listed. Include the name, address and phone number of the individual(s).
----------------------------------------------------------------
Public Records and Phone Records Listings
DEFRANK, EDMUND
823 WASHINGTON ST, SPENCERPORT, NY 14559-9703.
Phone Number 585-352-9218
ODELL, E
BRIGHTON, NY 12970.
Phone Number 585-327-3686
DEFRANCO, FRANK
6 REX LN, SPENCERPORT, NY 14559-9700
DR. OBRECT, MICHAEL
200 RED CREEK DR, HENRIETTA, NY 14467
Phone Number +1 (585) 334-0352
FRANCIS, PAUL
37 TROTTER DR, HENRIETTA, NY 14467-9769.
Phone Number 585-334-7733
CARLSON, BRITA
1 BURKE LN #D, SPENCERPORT, NY 14559-1546.
Phone Number +1 (585) 3529383
EDWARDS, SUSAN
4621 W RIDGE RD, SPENCERPORT, NY 14559-1552.
Phone Number
CARLSON, JEFF
21 NEVINS RD, HENRIETTA, NY 14467-9307.
Phone Number 585-359-9545
FRANCIS, RICHARD
13 LINDA LN, SPENCERPORT, NY 14559-1613.
Phone Number
DEFREZE, GREGORY
10 BIG RIDGE RD, SPENCERPORT, NY 14559-1219.
Phone Number 5853520978
ENGLEHARDT, HERBERT
75 TOTTENHAM RD, BRIGHTON, NY 14610-2244.
Phone Number 585-482-2955
CARTER, GARY
204 PINE HILL RD, SPENCERPORT, NY 14559-1010.
Phone Number (585)352-8826
DEGEN, MARK
27 COBRA DR, HENRIETTA, NY 14467-9512.
Phone Number 585-321-3524
DEGENNARO, VICTOR
537 WASHINGTON ST, SPENCERPORT, NY 14559-9539.
Phone Number +1 (585) 352-3824
FRANCIS, THOMAS
4812 LYELL RD, SPENCERPORT, NY 14559-2014.
Phone Number 585-352-4758
CARTER, LINDA
50 JORDACHE LN, SPENCERPORT, NY 14559-2059.
Phone Number 585-352-4913';
my $regex = qr/\+?[\d]?\s*\(?\d{3}\)?[\s\.-]?\d{3}[\s\.-]?\d{4}/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