use strict; use warnings; my @valid_candidates = ( 'Alice', 'Bob', 'Charlotte', 'David', 'Eve' ); my %tally_for = map { lc($_) => 0 } @valid_candidates; print "Welcome to the Die Bold 691549 Electrified Voter Motor\n"; print "Your candidates are:\n"; print map { "$_\n" } sort @valid_candidates; print "Enter one name per line, end with EOF.\n"; while ( my $candid_date = lc <> ) { chomp $candid_date; if ( exists $tally_for{ $candid_date } ) { $tally_for{ $candid_date }++; } else { warn "Write-in for $candid_date\n"; $tally_for{ $candid_date }++; } } my @winner_first = reverse sort { $tally_for{$a} <=> $tally_for{$b} } keys %tally_for; foreach my $who ( @winner_first ) { printf "%10s : %d\n", $who, $tally_for{$who}; }