#! perl -slw use strict; use Data::Dumper; my( @data, $current ); while( ) { if( my ($host,$ip,$brand) =/^(\w+)\s+(\S+)\s+(\S+)/ ) { $current and push @data, $current; $current = {HOST=>$host, IP=>$ip, BRAND=>$brand}; next; } my( $key, $val ) = m[\s+(.+)\s+(\S+)$] or next; $current->{$key} = $val; } $current and push @data, $current; print Dumper \@data; __DATA__ Hostname1 1.1.1.1 Cisco Chassis Serial Number xyz123 Interface Gig0/0/31 Hostname2 2.2.2.2 Juniper Chassis Serial Number abc123 Interface Gi-0/0/31