#!/usr/bin/perl use strict; use warnings; my $section = "unknown"; my %volumes; # volumes for each host, keyed by host name my %capacities; # capacity of each volume, keyed by volume name while(my $line = ) { chomp($line); if ( $line =~ m/^host_output$/) { $section = "host_output"; my $discard = ; # discard the header line } elsif ( $line =~ m/^volume_output$/) { $section = "volume_output"; my $discard = ; # discard the header line } elsif ( $line =~ m/^$/) { $section = "unknown"; } elsif ($section eq "host_output") { my ($volume, $host) = split(/\s+/,$line); push(@{$volumes{$host}}, $volume); } elsif ( $section eq "volume_output" ) { my ($volume, $capacity) = split(/\s+/,$line); $capacities{$volume} = $capacity; } } foreach my $host (sort keys %volumes) { foreach my $volume (@{$volumes{$host}}) { print "$host: $volume: $capacities{$volume}\n"; } } __DATA__ host_output volume_name host_name vol1 host1 vol2 host1 vol3 host1 vol4 host2 vol5 host2 vol2 host2 volume_output volume_name size vol1 10g vol2 20g vol3 30g vol4 30g vol5 20g