#!/usr/bin/perl use warnings; use strict; my %zone; my $section = 0; my ($current_zone, $current_cluster); while (<>) { if (! $section) { if (/^Zone ID/) { $section = 'zones'; } elsif (/^Cluster ID/) { $section = 'clusters'; } elsif (/^Host Name/) { $section = 'hosts'; } elsif (my ($name) = /^(\S+)$/) { if (exists $zone{$name}) { $current_zone = $name; } elsif (exists $zone{$current_zone}{cluster}{$name}) { $current_cluster = $name; } } } elsif ('zones' eq $section) { if (my ($id, $name) = /(\S+)\s+(\S+)/) { $zone{$name}{id} = $id; } elsif (/^$/) { $section = 0; } } elsif ('clusters' eq $section) { if (my ($id, $name, $type, $mem, $cpu) = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ ) { $zone{$current_zone}{cluster}{$name} = { id => $id, type => $type, mem => $mem, cpu => $cpu }; } elsif (/^$/) { $section = 0; } } elsif ('hosts' eq $section) { if (my ($host, $vms, $status, $state) = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ ) { $zone{$current_zone}{cluster}{$current_cluster}{host}{$host} = { vms => $vms, status => $status, state => $state }; } elsif (/^$/) { $section = 0; } } } use Data::Dumper; print Dumper \%zone;