Not that there's anything wrong with the above answers, but surely the reason for the specific problem:
if you enter nothing and hit enter it yields the username and password you have entered previously
Is that if you do that, you're doing the regex with an empty string. Which matches.
You're essentially doing if ($key =~ m//i) if they just hit return.
So you need another if clause as well as the one for "if it's 'exit'" which says what to do if it's empty.
Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...