use strict; use warnings; use Data::Dumper; my ($mac, %data); while ( ) { if ( /^Ethernet address: ([0-9a-f]{12}) \(([^\)]+)/ ) { $mac = $1; $data{$mac}{device} = $2; next; } if ( /(Incoming|Outgoing) total ([0-9]+) packets/ ) { $data{$mac}{$1} = $2; next; } if ( /Average rates: ([0-9\.]+) kbytes\/s incoming, ([0-9\.]+) kbytes\/s outgoing/ ) { $data{$mac}{incomingRate} = $1; $data{$mac}{outgoingRate} = $2; } } print Dumper (\%data); __DATA__ Ethernet address: 009096c7cf98 (ADSL Modem) Incoming total 297089 packets, 45056408 bytes; 293887 IP packets Outgoing total 401212 packets, 252051283 bytes; 398003 IP packets Average rates: 0.47 kbytes/s incoming, 2.63 kbytes/s outgoing Last 5-second rates: 0.00 kbytes/s incoming, 0.00 kbytes/s outgoing Ethernet address: 0020ed7924c2 (Debian Router ext) Incoming total 401212 packets, 252051283 bytes; 398003 IP packets Outgoing total 297096 packets, 45056702 bytes; 293887 IP packets Average rates: 2.63 kbytes/s incoming, 0.47 kbytes/s outgoing Last 5-second rates: 0.00 kbytes/s incoming, 0.00 kbytes/s outgoing