in reply to Re^4: Word Count and Match
in thread Word Count and Match

When matching, use anchors in the regex to only match the whole word:
my $namecnt = qr/^(David|Tom|Sam|Will|Dave|William|Thomas)$/;
^ matches at the beginning, $ matches at the end.

The match will now look like (I removed the /o as it's not recommended)

if ($word =~ /$namecnt/i) {

Note that the first argument to split is a regex. It's clearer to write

my @words = split /:/;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]