use vars '$obtain_country'; sub Obtain_GeoIP { ... $obtain_country ||= $obtain_country = $dba->prepare("select Country from GeoIP where $lip between Start_int and End_int limit 1"); };