use strict; use warnings; use Text::ExtractWords qw(words_count); my %words; my @paraStats; local $/ = '-100'; while () { chomp; s/[\n\r]/ /g; my %paraWordFreq; words_count(\%paraWordFreq, $_, minwordlen => 4); push @paraStats, {%paraWordFreq}; map {$words{$_} = 0} keys %paraWordFreq; } my $col = 0; print ' ' x 17; for (sort keys %words) { next if 4 > length $_; $words{$_} = ($col += 1 + length $_); print "$_ "; } my $paraNum = 1; for (@paraStats) { printf "\nParagraph %5d: ", $paraNum++; my $col = 0; my %paraWords = %$_; for (sort keys %paraWords) { next if 4 > length $_; printf "%*d ", $words{$_} - $col - 1, $paraWords{$_}; $col = $words{$_}; } } __DATA__ The first row is top 100 frequent words (in the text file). Numbers in each cell shows the frequency of the word in the data. The data is one text file (.txt) with more than 100000 words. -100 Each "paragraph" is delimited by "-100". I need a matrix which shows the frequency of each word in each paragraph. I thought it is words-by-words matrix, but it's wrong. It's words-by-paragraph matrix. Thank you very much! Peace of the world. #### 100000 cell data delimited each file first frequency frequent it's matrix more much need numbers paragraph peace shows text than thank thought very which with word words words-by-paragraph words-by-words world wrong Paragraph 1: 1 1 2 1 2 1 1 1 1 1 1 2 1 1 1 2 Paragraph 2: 1 1 1 Paragraph 3: 2 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1