my %H; while (<>) { my @words = map { lc } # map all words to lower case split /\s+/, $_; # break $_ into a list of words $H{$_}++ for @words; # add words to hash }