#!/usr/bin/perl my %percents; my %gdps; sub nospace { foreach (@_) { $$_ =~ s/^\s*(.*?)\s*$/$1/; } } open EDUCATION, '<', '/tmp/education'; while () { my ($country, $percent, @rest) = split /\t/; nospace(\$country, \$percent); $percents{$country} = $percent; } close EDUCATION; open GDP, '<', '/tmp/gdppc'; while () { my ($rank, $country, $gdp, @rest) = split /\t/; nospace(\$country, \$gdp); $gdp =~ y/,//d; $gdps{$country} = $gdp; } close GDP; my @topcountries; while (my ($country, $percent) = each %percents) { if (exists($gdps{$country})) { push @topcountries, [$country, $gdps{$country} * $percent / 100]; } } @topcountries = sort { $b->[1] <=> $a->[1] } @topcountries; foreach (@topcountries) { print "$_->[0]: $_->[1]\n"; }