use strict; use warnings; #open IN, "count.txt"; my @words = qw(this and led cain had been indwelt by an adjuster had always been disdainful he and when he had sought divine assistance an adjuster indwelt and this adjuster gave cain); my @counted =(); while (@words) { my $key = shift @words; my $count = 1; foreach my $y (0..$#words) { if (not $words[$y]) {next} # Avoids absent members resultant from splice. if ($words[$y] eq $key) { $count++; splice (@words, $y, 1); } } push @counted, "$key\t$count\n"; } print sort @counted;