{ "1427766555" => { bob => 10 }, "1427766556" => { bill => 5 }, "1427766557" => { bob => 12 }, } #### #! perl use strict; use warnings; my (%names, %times); while () { chomp; my ($value, $time, $name) = split /,\s*/; next unless defined $name; $names{$name} = undef; $times{$time}->{$name} = $value; } print join(',', 'time', sort keys %names), "\n"; for my $time (sort keys %times) { print $time, ','; for my $name (sort keys %names) { print +(exists $times{$time}->{$name}) ? $times{$time}->{$name} : '', ','; } print "\n"; } __DATA__ 12,1427766557, bob 5,1427766556, bill 10,1427766555, bob #### 13:55 >perl 1224_SoPW.pl time,bill,bob 1427766555,,10, 1427766556,5,, 1427766557,,12, 13:55 >