use strict;
my $str = 'PO BOX number 1234, CA - 3265 TEL: +1-200-200-2000 FAX: +1-200-200-2001
PO BOX number 1234, CA - 3265 Service: +1-200-200-2002 \\ +1-200-200-2022 F : +1-200-200-2003
PO BOX number 1234, CA - 3265 care: +1-200-200-2004 f : +1-200-200-2005
PO BOX number 1234, CA - 3265 fire: +1-200-200-2006 fax : +1-200-200-2007
PO BOX number 1234, CA - 3265 help: +1-200-200-2008 fax - +1-200-200-2009
PO BOX number 1234, CA - 3265 fax : (+123)-4567890 \\ (+123)-4567891
(?:(f|F)((a|A)(X|x))?';
my $regex = qr/(?:(f|F)((a|A)(X|x))?(?:\s?(\-|\:)?\s?))(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30}(*SKIP)(*FAIL)|(?:\s?[0-9\+\.\(\)\/\\\-]\/?\\?\s?){7,30}/p;
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