in reply to
Using Word Tokens as Features
Rather than building up the "columns" (almost certainly a "hash" in Perl) one new word at a time, I'd suggest that you start out with a reasonably complete corpus for the language/subject you wish to cover. This will make it a bit easier to maintain counts between messages and the number of zero columns for a particular message won't depend on the order it was processed (otherwise, your first message would have no zero columns).
As for the word counting task itself, look into split and hash. The basic procedure is rather simple but you'll need to decide how to handle case, hyphenation and maybe even stemming.