I understand that you are not looking for a solution, but I still recommend that you avoid the problem by using a prompt module (my favorite is
IO::Prompt::Hooked). This module handles the prompt, chomp, and empty string correctly without your writing any code at all. It provides options to specify error detection and processing.