Far from me to accuse your code, rather I'm thankful for showing it to me, it's just that while Perl is a great language for coding (and damn logical on its syntax), there are far too many elements that still appear extremely obscure to me. My main issue was that you didn't seem to have a handle <FILE> which I assumed to be a requirement for reading files, and then this line:
my @words = split /\W+/, do { local $/ = <$infile> };
thank you very much however for explaining the local scope of $/. that will most certainly come in handy in the upcoming term.