in reply to Word density

I think that is one wheel you really don't want to re-invent. See Text::ExtractWords. Also, you won't want to forget to account for stop words. See Lingua::StopWords.

There are also some "N-gram" modules that you might find useful for your main algorithm. (Ignore the "tangram" hits.)

Also, it looks to me like what you're trying to do can be achieved, more or less, by a combination of Lingua::EN::Summarize and Lingua::EN::Keywords.

We're building the house of the future together.