use strict;
my $str = 'RECOVER FROM:
LUFTHANSA CARGO - FRA
FLIGHT: LH441
ETA: SUN 25-APR-2021 09:09
WAYBILL: 020-90350573
ORIGIN: IAH
SERVICE: ZXO Courier Solution
x0Wx0H in. 109 lbs (49.0 kg) Skid
DELIVER TO:
VITESCO TECHNOLOGIES CZECH REPUBLIC S.R.O
VOLANOVSKA 518
TRUTNOV 541 01 CZ
ATTN: ADAM STUCHLIK
PHONE: +420 731 593 139
EST. DISTANCE: 293 miles
PCS/WT: 1 / 49.0 kg (109 lbs)
DIMS: 1@82x82x51cm
ORDER#: 10659800
CONTENTS: PCV PANNEL
SERVICE: Next Flight Out(NFO)
URGENT! PLEASE CONFIRM THIS ALERT BY EMAILING CnwGermanyOps@cnwglobal.com OR CALLING COURIER NETWORK INC. AT 800-852-2282';
my $regex = qr/\bDELIVER TO:\R\h*(\S+).*(?:\R.*){2}.*\h(\S+)/p;
if ( $str =~ /$regex/ ) {
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