in reply to Most efficient design

Someone else pointed out that you have a recursion loop.

Reading the code, I think you would benefit from given/when instead of a cascade of elsif statements.

But... maybe you should make a hash as a keyboard mapping. This will not only make your loop simple as all the logic is elsewhere, but allow you to remap the keyboard.

my $key = ReadKey(-1); next unless defined $key; #next or return depending on your code stru +cture if ($key eq "\e") { #expecting more $key .= ReadKey(-1); # should be a '[' $key .= ReadKey(-1); } my $callback= $keymap{$key}; if (defined $callback) { $callback->($key); } else { beep(); } #no such key is meaningful here
That is, the gathering is centralized, and separate from the code dispatched to. The $key is passed as an argument in case you have common subs for several keys and need to distinguish between them.

—John