open (FILE, 'data.txt') || die "Unable to open file"; while () { $line=$_; if ($line =~ /Folder/ || $line eq ""){ next; } ($type,$name)=split(/:/); $type =~ s/^\s+//; $type =~ s/\s+$//; $name =~ s/^\s+//; $name =~ s/\s+$//; if ($type=~"Host"){ $host=$name; }elsif ($type=~"VM"){ $guest=$name; push @{$hash{$host}}, $guest; } }