use strict; # make up some data my $line = "('The text.')-- 5 o'clock! What's cookin' with the text data?"; # split on whitespace, keep only tokens that contain at least on letter my @words = grep /\p{L}/i, split ' ', $line; my %wcount; for ( @words ) { # using $_ will modify @words "in-place" s/^\P{L}+//; # remove initial non-letters s/\P{L}+$//; # remove final non-letters $wcount{lc()}++; # normalize to lower-case-only } print "$wcount{$_}\t$_\n" for ( sort keys %wcount ); __OUTPUT__ 1 cookin 1 data 1 o'clock 2 text 2 the 1 what's 1 with