#! /usr/bin/perl use strict; my %test = ( question1 => 'a', question2 => 'b', question3 => 'a', ); #my hash of arrays with multiple answers my %answers = ( question1 => [ 'a' ], question2 => [ 'b', 'd' ], question3 => [ 'b' ], ); my $q_count = keys %answers; my $grade = 0; for ( keys %answers ) { $grade++ if "@{$answers{$_}}" =~ /$test{$_}/i; } print "You got $grade out of $q_count right.$/";