Here's one way to do it:
my(@words, %count, $word); # (optionally) declare our variables
chomp(@words = <STDIN>);
foreach $word (@words) {
$count{$word} += 1; # or $count{$word} = $count{$word} + 1;
}
foreach $word (keys %count) { # or sort keys %count
print "$word was seen $count{$word} times.\n";
}
In this one, we declared all of the variables at the top. People who come to Perl from a background in languages like Pascal (where variables are declared at the top) may find that way more familiar than declaring variables as they are needed. We're declaring these because we're pretending that use strict may be in effect; by default, Perl won't require such declarations.
Next, we use the line-input operator, <STDIN>, in a list context to read all of the input lines into @words and then we chomp those all at once. So, @words is our list of words from the input if the words were all on separate lines as they should have been.
The first foreach loop goes through all of the words. That loop contains the most important statement of the entire program, the statement that says to add one to $count{$word} and put the result back into $count{$word}. Though you could write it the short way (with the += operator) or the long way, the short way is a little bit more efficient since Perl has to look up $word in the hash only once. For each word in the first foreach loop, we add one to $count{$word}. If the first word is fred, we add one to $count{"fred"}. Since this is the first time we've seen $count{"fred"}, it's undef. We're treating it as a number (with the numeric += operator, or with +, if you wrote it the long way), so Perl converts undef to 0 for us, automatically. The total is 1, which is stored back into $count{"fred"}.
The next time through that foreach loop, let's say the word is barney. We add one to $count{"barney"}, bumping it up from undef to 1, as well.
Suppose the next word is fred again. When we add one to $count{"fred"}, which is 1, we get 2. This goes back into $count{"fred"}, meaning that we've seen fred twice.
When we finish the first foreach loop, then we've counted how many times each word has appeared. The hash has a key for each (unique) word from the input, and the corresponding value is the number of times that word appeared.
The second foreach loop goes through the keys of the hash, which are the unique words from the input. In this loop, we'll see each different word once. For each one, it says something like "fred was seen 3 times."
If you want the extra credit on this problem, you could put sort before keys to print out the keys in order. If there will be more than a dozen items in an output list, it's generally a good idea to sort them, so that a human being who is trying to debug the program will fairly quickly be able to find the item she wants.