Perl - how to open a file, count the instances of a word inside it and output that #?

Mizugori

Senior member
May 3, 2007
496
0
0
I need to write a perl script that can be run from the command line, and will count the number of times a word appears in a text file (this word doesn't need to be a variable it can just be hard coded into the program) and then print on the screen how many times the word was found in the text file. i want it to be command-line capable so like if im in unix i could just type

perl filename.txt

and it would output a number. right now i need it to count the word "then."

can anyone help me with this? please note, this is not homework lol. i just don't understand some of the examples in my "learning perl" book (ie 'the llama book').