use warnings; use strict; use Data::Dumper; $Data::Dumper::Sortkeys=1; my %list; while () { my ($k, $v) = split; $list{$k}{$v}++; } for my $k (keys %list) { for my $stat (qw(active passive failed other)) { $list{$k}{$stat} = 0 unless exists $list{$k}{$stat}; } } print Dumper(\%list); =for output $VAR1 = { 'lun1' => { 'active' => 2, 'failed' => 1, 'other' => 0, 'passive' => 0 }, 'lun2' => { 'active' => 0, 'failed' => 0, 'other' => 0, 'passive' => 1 }, 'lun3' => { 'active' => 0, 'failed' => 0, 'other' => 1, 'passive' => 0 } }; =cut __DATA__ lun1 active lun2 passive lun1 failed lun3 other lun1 active