foreach $k(sort {$match{$a}<=>$match{$b}} keys %match} I get an error, "Can't use "my $b" in sort comparison at D:\db\New\est_keywords.pl line 41." #### foreach $word(sort byval keys %match) { if ($match{$word} < 3) {next;} print "$word\t$match{$word}\n"; } } sub byval { return $match{$b} <=> $match{$a}; }