#! perl -slw use strict; use Data::Dump qw[ pp ]; my %hash; while( ) { chomp; my $r = \%hash; my @bits = split '\s+->\s+|_', $_; $r = $r->{ shift( @bits ) } //= {} while @bits > 2; $r->{ $bits[ 0 ] } = $bits[ 1 ]; } pp \%hash; __DATA__ Host_001 -> objectID -> HOST.62 Host_001 -> name -> rapidqa Host_001_WWN_001 -> WWN -> 21.00.00.E0.8B.80.7E.7D Host_001_WWN_002 -> WWN -> 21.00.00.E0.8B.80.E7.7F Host_001_LogicalUnit_001 -> objectID -> LU.R700.87108.8234 Host_001_LogicalUnit_001 -> devNum -> 8234 Host_001_LogicalUnit_002 -> objectID -> LU.R700.87108.8235 Host_001_LogicalUnit_002 -> devNum -> 8235 Host_002 -> objectID -> HOST.107 Host_002 -> name -> sapfvir03 Host_002_WWN_001 -> WWN -> 21.00.00.E0.8B.81.D7.F6 Host_002_WWN_002 -> WWN -> 21.00.00.E0.8B.81.4C.F9 Host_002_LogicalUnit_001 -> objectID -> LU.R700.87108.10336 Host_002_LogicalUnit_001 -> devNum -> 10336