my %freq; while (<$fh>) { chomp; $freq{$_}++ for split //; } my $tot = sum(values %freq); for (keys %freq) { $freq{$_} = 1 - ($freq{$_} / $tot); } sub score { my ($word) = @_; my $score = 0; $score += $freq{$_} for split //, $word; return $score; }