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

In reply to Re: a question about making a word frequency matrix by TedPride
in thread a question about making a word frequency matrix by peacekorea

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.