my @paths; sub get_paths { init_paths unless @paths; return @paths; } sub init_paths { ... # logic to initialize your path list }