use strict; use warnings; my $string = <\S+)\s+ IP\saddr:\s(?\S+)\s+(?\S+) .+? Link\sCost:\s(?\S+)\s+ Link\sSpeed:\s(?\S+)\sMbps /sxg ) { print "Node with MAC address: $+{mac} has IP = $+{ip1}, $+{ip2} " . "and Link Speed = $+{speed} and Link Cost = $+{cost}\n"; } #### Node with MAC address: xx:aa:aa:aa:aa:aa has IP = a.b.c.d, x.y.z.f and Link Speed = xx and Link Cost = xx Node with MAC address: xx:aa:aa:aa:aa:aa has IP = a.b.c.d, x.y.z.f and Link Speed = xx and Link Cost = xx