in reply to count words in a line

Sure you can. If your data is nice and normal like in the first example you can do something like this.
@sentence = split /\s/,"perlmonk perlmonk perlmonk "; $numWords = @sentence;

to count the number of occurrences of perlmonk and not other words you could use the same idea but with a regular expression. I will leave it to you to figure it out. This is a clunky way to do it....
@sentence = split /\s/,"perlmonk perlmonk perlmonk and some other wor +ds that are not perlmonk"; foreach $word (@sentence) { if ( $word =~/perlmonk/) { $numOccur++; } }
The last one would be more tricky, but it can be done with a fairly easy regxp... something along the lines of  /p\s*e\s*..... should do the trick
Good luck.
Disclamer: all code untested and off the top of my head.