$file=~s/\W//sg; ## remove all alphanumeric characters from all the file.
@words=split( /\s+/, $file); ## put all words in @words.
my @good_words=();
foreach (@words) {
push @good_words, $_ if length $_ < 5; ## lose words shorter than 5 characters
}
## do with @good_words whatever you want