A few hints to get you pointed in the right direction:
- Words like the and of are called stop words. You can eliminate them first, compiling a list of stop words or using something like Lingua::StopWords.
- A way to choose n items from a set of m is called a combination, and a module like Math::Combinatorics can help you find these combinations.
Good luck!