I see two options:
- As per your script, you populate %hash and
%population%location in such a way that they have the same keys. So you could just move the print statement from your "locations" loop into the "users" loop (it would also make sense to rename %hash to %users).
- Alternatively, you could add another dimension to your %hash such that you store both times and locations in the hash. For example:
push (@{$hash{$word2}{'times'}},$word1);
push (@{$hash{$word2}{'locations'}},$word3);
This way you would keep the data closer together.
EDIT: Changed %population to %location (thanks kcott)