use strict;
my $str = 'Router# show ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/1 unassigned YES unset up up
GigabitEthernet0/2.1 192.168.190.235 YES unset up up
GigabitEthernet0/3 unassigned YES unset up up
GigabitEthernet0/4 192.168.191.2 YES unset up up
TenGigabitEthernet2/1 unassigned YES unset up up
TenGigabitEthernet2/2 unassigned YES unset up up
TenGigabitEthernet2/3 unassigned YES unset up up
TenGigabitEthernet2/4 unassigned YES unset down down
GigabitEthernet36/1 unassigned YES unset down down
GigabitEthernet36/2 unassigned YES unset down down
GigabitEthernet36/11 unassigned YES unset administratively down down
GigabitEthernet36/25 unassigned YES unset down down
Te36/45 unassigned YES unset down down
Te36/46 unassigned YES unset down down
Te36/47 unassigned YES unset down down
Te36/48 unassigned YES unset down down
Virtual36 unassigned YES unset up up';
my $regex = qr/(?P<interface>\w+(?:\d/?)+(?:[\.]\d{1,3})?)\s+(?P<ip_address>(?:\w[\.]?)+)\s+(?P<ok>\w+)\s+(?P<method>\w+)\s+(?P<status>(?:\w+\s)?[\w]+)\s+(?P<protocol>\w+)/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