use strict;
my $str = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EGE_Booking>
<TripID>1004-3637-360</TripID>
<RecordLocator>1004-3637-360</RecordLocator>
<Travelers>
<Traveler>
<PerCode>13593199</PerCode>
<FirstName>Claude</FirstName>
<LastName>Christensson</LastName>
<ContactDetails>
<Email>claude.christensson@wirelesscar.com</Email>
<MobilePhone>46765537005</MobilePhone>
</ContactDetails>
<TravellerCostCenter>
<CostCenter Code="CC3">
<Label>Employee ID</Label>
<Value>56524</Value>
</CostCenter>
<CostCenter Code="CC4">
<Label>Global Department code</Label>
<Value>DI43400</Value>
</CostCenter>
</TravellerCostCenter>
</Traveler>
</Travelers>
<Segments>
<HotelSegment>
<HOTEL>
<TripItemID>5a7dc8f971ac0163f7563e7e</TripItemID>
<PNR>ABC1DS</PNR>
<Status>V</Status>
<CheckInDate>2018-02-13</CheckInDate>
<CheckOutDate>2018-02-14</CheckOutDate>
<Vendor SupplierType="11281422">Genting Hotel</Vendor>
<PropertyName>Genting Hotel</PropertyName>
<Location>
<Name>Pendigo Way, England, B40 1PU</Name>
<City>Birmingham</City>
<Country Code="GBR">Storbritannien</Country>
</Location>
<ConfirmationCode>982674693</ConfirmationCode>
<Cost>
<Amount>751.08</Amount>
<Currency Code="SEK">Swedish Krona</Currency>
</Cost>
<OutOfPolicyReasons/>
</HOTEL>
<HOTEL>
<TripItemID>5a7dc8f971ac0163f7563e7e</TripItemID>
<PNR>55545261643</PNR>
<Status>V</Status>
<CheckInDate>2018-02-13</CheckInDate>
<CheckOutDate>2018-02-14</CheckOutDate>
<Vendor SupplierType="11281422">Genting Hotel</Vendor>
<PropertyName>Genting Hotel</PropertyName>
<Location>
<Name>Pendigo Way, England, B40 1PU</Name>
<City>Birmingham</City>
<Country Code="GBR">Storbritannien</Country>
</Location>
<ConfirmationCode>982674693</ConfirmationCode>
<Cost>
<Amount>751.08</Amount>
<Currency Code="SEK">Swedish Krona</Currency>
</Cost>
<OutOfPolicyReasons/>
</HOTEL>
</HotelSegment>
</Segments>
<Invoicing>
<CompanyCode>28781</CompanyCode>
<ClientNumber>28781</ClientNumber>
<ClientRequisition>claude.christensson@wirelesscar.com</ClientRequisition>
<ClientReference>689100277</ClientReference>
<ClientCostCenter>
<CostCenter Code="CC1">
<Label>Legal Entity</Label>
<Value>WirelessCar Sweden AB</Value>
</CostCenter>
<CostCenter Code="CC2">
<Label>Cost Center</Label>
<Value>989502</Value>
</CostCenter>
</ClientCostCenter>
</Invoicing>
</EGE_Booking>
';
my $regex = qr/(?ms)<PNR>([\w]+)<\/PNR>
/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