foreach $word (sort keys %hash) { print "$word\n"; } print "\n"; foreach $word (sort keys %hash) { if ($hash{$word} > 1) { print "$word\n"; } }