in reply to Most efficient design

...but my current code eats up memory almost right away.

As it is, you have an endless recursion, i.e. UserInput() calls updateScreen(), which then calls userInput(), etc...  Every stack frame needs memory, which quickly adds up. And as the functions never return, the memory won't be freed.

You probably want one main loop that's checking for user input, simply calling updateScreen() from there whenever needed  (without updateScreen() calling userInput() again...).

Something like this  (renaming userInput to mainLoop, letting userInput just get the keys... — this is not essential, of course):

... sub mainLoop { while (1) { $key = userInput(); if ($key eq "...") { # do something } ... updateScreen(); } } sub userInput { #... } sub updateScreen { #add code to refresh screen } mainLoop(); ...