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