#to count the words: use Data::Dumper; my %words; while () { my @these_words = split(' ', $_); foreach my $this_word (@these_words) { $words{$this_word}++; } } print Dumper \%words;