#!/usr/bin/perl # countletters.pl # usage, to count the letters in foo.txt: # countletters.pl < foo.txt $total = 0; while (<>) { chomp; s/\s+//g; @c = split(//,$_); for $c (@c) { if ($c =~ /[A-Za-z]/) { $chars{uc($c)}++; $total++; } } } print "$total characters read\n"; for $k (keys %chars) { print 100*$chars{$k}/$total," $k\n"; }