use strict;
my $str = 'SITE_VPLEX:
RPAs:
RPA 1:
Version: 4.1.SP1.P1(h.167)
WAN IP: 000.000.000.000
RPA LAN IPv4: 000.000.000.000
RPA LAN IPv6:N/A
iSCSI interface IPs: None
Interfaces:
Type: FC
Initiator ID: 50012481006bexxx
Type: FC
Initiator ID: 50012481006bexxx
Type: FC
Initiator ID: 50012481006bexxx
Type: FC
Initiator ID: 50012481006bexxx
Hardware details:
Hardware type: Intel Corporation S2600GZ GEN5
Adapter type: 2564
Vendor: Intel Corporation
Hardware Serial ID: FC6RP133000229_00000000002_FFF
Hardware Platform: Intel Corporation S2600GZ GEN5
Amount of memory: 16269416 KB
Number of CPUs: 12
RPA 2:
Version: 4.1.SP1.P1(h.167)
WAN IP: 000.000.000.000
RPA LAN IPv4: 000.000.000.000
RPA LAN IPv6:N/A
iSCSI interface IPs: None
Interfaces:
Type: FC
Initiator ID: 50012481006bdxxx
Type: FC
Initiator ID: 50012481006bdxxx
Type: FC
Initiator ID: 50012481006bdxxx
Type: FC
Initiator ID: 50012481006bdxxx
Hardware details:
Hardware type: Intel Corporation S2600GZ GEN5
Adapter type: 2564
Vendor: Intel Corporation
Hardware Serial ID: FC6RP133000135_0000000000_FFF
Hardware Platform: Intel Corporation S2600GZ GEN5
Amount of memory: 16269416 KB
Number of CPUs: 12';
my $regex = qr/(?ms)(RPA\s1:).+?Initiator\sID:\s(?<RPA1Initiator>[^ ]*)/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