in reply to infinite loop does not stop

You may want to chomp (my $answerinfect = <>); because otherwise it would contain "entered_answer\n". Does this give you any warnings?

What scope does the $j variable belong to? Did you try last instead of setting variable?

Sorry if my advice was wrong.