use strict; use warnings; use Text::ASCIITable; use open qw(:std :utf8); my %hash; my $tb = Text::ASCIITable->new(); $tb->setCols( 'WordF1', 'WordF2', 'Difference' ); while (<>) { next if $. < 3; push @{ $hash{$1} }, $2 while /\|\s+(\w+)\s+\|\s+([.\d]+)/g; } for my $word ( keys %hash ) { if ( @{ $hash{$word} } == 2 ) { $hash{$word} = $hash{$word}->[0] - $hash{$word}->[1]; } else { delete $hash{$word}; } } for my $word ( sort { $hash{$b} <=> $hash{$a} } keys %hash ) { $tb->addRow( $word, $word, sprintf( '%0.05f', $hash{$word} ) ); } print $tb;