in reply to how to check for keyboard input
Check out Term::ReadKey. Its synopsis almost exactly shows what you want.