Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade.
I have:

if ( $response =~ m/^[q]/ ) {
$user_wants_to_quit = 1; 
 } else {
if ( $response == $solution ){
print "Correct!\n";
$correct = $correct + 1      
} else {
print "Incorrect: $question $solution \n"; 
$incorrect = $incorrect + 1 	      
} 
    			
}

} 

I want to insert

print "You got $correct answers and $incorrect answers"

but I do not know how to insert it into what I already have

Is this a homework assignment for a programming class?

What operating system and shell are you using?

Other than not printing statistics at the end of a session, is your script working correctly?

Does the system you're using have the game named quiz installed? Can you give it a new quiz file to get what you want without writing a new program to do the same thing?