in reply to a question about making a word frequency matrix

The following does what you want. Note that I've excluded all 1 and 2-letter words, plus and and the. You may wish to add to the exclusion list. Also note that I have not provided for the situation where a paragraph word count goes over 999 for a 3-letter word. I didn't feel this was necessary.
use strict; use warnings; my (%count, @pcount, @words, @values, $format, $i); my @remove = qw/and the/; # Words to exclude my $width = 10; # Number of words to display $/ = '-100'; # Line delimiter while (<DATA>) { my %pcount; $_ = lc $_; while (m/[a-z]+('[a-z]+)?/g) { next if length($&) < 3; $pcount{$&}++; $count{$&}++; } push @pcount, \%pcount; } for (@remove) { delete $count{$_} if exists $count{$_}; } @words = sort {$count{$b} <=> $count{$a} || $a cmp $b} keys %count; $#words = $width - 1 if $#words > $width - 1; $format = '%' . length($#pcount+1) . 's'; $format .= '%' . (length($_) + 2) . 's' for @words; print ' 'x10, sprintf($format, '', @words), "\n"; for ($i = 0; $i <= $#pcount; $i++) { my @values = $i + 1; push @values, $pcount[$i]{$_} for @words; no warnings; print 'paragraph ', sprintf($format, @values), "\n"; } push @values, $count{$_} for @words; print "\n", ' 'x10, sprintf($format, '', @words), "\n"; print ' 'x10, sprintf($format, '', @values), "\n"; __DATA__ So it was into a neighborhood bursting with rumors and resentment that + Gopi, the ten year old cousin who had been brought down from the vil +lage to be the household help, stepped out to do his daily chores. Hi +s responsibilities included:-100 1. Carrying the copper tray for the old lady and trotting behind her a +t the proper pace when she went out to do her morning prayers at five + am in the morning.-100 2. Bringing the wood, the coal, and the kindling so that the daughter- +in-law could light the fire.-100 3. Bringing water from the well to the fifth floor, where the kitchen +was located.-100 4. Cutting the vegetables, cleaning the rice, soaking the lentils, she +lling the peas and any other sundry time-consuming tasks that arose i +n a kitchen with a mortar and pestle and precious little else.-100
Output:
that bringing from her his kitchen morning old paragraph 1 1 1 2 1 paragraph 2 2 2 1 paragraph 3 1 1 paragraph 4 1 1 1 paragraph 5 1 1 that bringing from her his kitchen morning old 3 2 2 2 2 2 2 2