use Data::Dumper; use strict; use warnings; my $words; while () { for (split) { $words->{$_} ++; } } print Dumper($words); __DATA__ three blind mice three blind mice see how they run