You did exactly what I suggested you don't do. Don't look at the whole. These are the things you actually need to do:
- Identify if a neighbourhood name starts with 'k'.
- Get a city's list of neighbourhoods.
- Get a province's list of cities.
- Identify if a province's name starts with 'c'.
- Get a country's list of provinces.
- Get a list of countries.
They're all independent. Nothing in there even suggests that you have a nested structure in memory.
The hard part:
if $neighbourhood_name =~ /^k/i;