my %counts;		#where we will count the words
if (open(my $in,"<","textToCount.dat")) {
    while (<$in>) {	#get each line, till done, into $_
        chomp $_;	#remove the end of line
        my @words = split(/[^\w']+/,$_); #split into words in @words
        map $counts{"\L$_"}++ , @words; #convert to lower case & count
    } #ready for the next line
} #the file is done
else {
    die "Failed to open the input file";
}

for (sort keys %counts) { #nice to be alphabetical
    print "$_: $counts{$_}\n";
}
