use strict;
my $str = 'Nov 1 00:00:21 akdcs20.ftc.abcd-ipsn AKDCS20 fpc0 LBCM-L2,brcm_port_learning_config(),1258:(brcm_port_learning_config:1258) Setting L2 learning unit:0,port_num:44, learn_flg 5
Nov 1 01:27:16 spnztpm01.abcd-ipsn 553177: LC/0/0/CPU0:Nov 1 01:27:16.040 : ifmgr[200]: %PKT_INFRA-LINEPROTO-5-UPDOWN : Line protocol on Interface TenGigE0/0/0/1.172153, changed state to Up
Oct 31 23:59:56 akdcs19.ftc.abcd-ipsn AKDCS19 ufdd[1679]: ufd_group_config_if_lookup ifname ae4 ';
my $regex = qr/^\w+\s+\d+\s+\d{2}(?::\d{2}){2}\s+(?P<devicename1>\S+)/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