Counting using tr.
#!/usr/local/bin/perl $countstring = "test"; @chars = split (/\s*/, $countstring); while ($input = <>) { $_ = $input; foreach $char (@chars) { eval ("\$count = tr/$char/$char/;"); $count{$char} += $count; } } foreach $char (sort (@chars)) { print ("$char appears $count{$char} times\n"); }