Yes, if you're coming from abroad and connecting flights in Lima, you'll need to go through customs and immigration before catching your connecting flight to Cusco.