use strict; use warnings; use Data::Dumper; { local $/ = undef; $_ = ; } my @words = split /[., \n]+/; print "$_\n" for @words; my $rhWords = {}; my $order = 0; foreach my $word (@words) { my $lcWord = lc $word; push @{$rhWords->{$lcWord}->{order}}, ++ $order; $rhWords->{$lcWord}->{count} ++; } my $dd = Data::Dumper->new([$rhWords], [qw(rhWords)]); print $dd->Dumpxs(); __END__ The quick brown fox jumps over the lazy dog, the slow brown duck swims over the muddy pond. The chicken is pecking in the yard until the quick brown fox decides he is hungry.