#!/usr/bin/perl use strict; use warnings; my $file = shift or die 'no file given'; # parse output file my $var = do $file; my %words; foreach my $col (sort keys %$var) { my $hash = $var->{$col}; # collect values for each word while (my ($k, $v) = each %$hash) { push @{ $words{$k} }, $v; } } foreach my $word (sort keys %words) { printf "%s %s\n", $word, join(' ', @{ $words{$word} }); }