use strict;
my $str = 'Parker Tech
74 Lincoln Green Lane
Church Stoke, PA 19402
(123) 456-7890
Invoice
Submitted on 9/9/2016
Invoice for
Name
Company name
Email
Street address
City, State, Zip
Payable to
Bobby John
Bobby Co.
bobby@john.com
Project
Project name
Invoice #
12345
Due date
9/16/2016
Description Qty Unit price Total price
Item #1 1 $200.00 $200.00
Item #2 2 $200.00 $400.00
$0.00
$0.00
Notes: Subtotal $600.00
Adjustments -$100.00
$500.00';
my $regex = qr/Item.+/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