#!/usr/bin/perl -w use IO::File; my $lilyRE = '\b([a-gs](is|es){0,2})(\d|\b)'; my %counters = (); for my $f (@ARGV) { my $io = IO::File->new($f); while ($_ = $io->getline) { chomp; my $note; while (($note) = /$lilyRE/o) { s/^.*?$note//; $counters{$note}++; } } } my $total = 0; foreach (keys %counters) { $total += $counters{$_}; } my %percent = (); foreach (keys %counters) { $percent{$_} = $counters{$_} / $total * 100; } foreach (keys %counters) { print $_, '=', $counters{$_}, ' ('; printf "%.2f", $percent{$_}; print '%)', "\n" ; } print "Total=$total\n";