To do it in one pass you can use this algorithm:
- Read one line
- If it is a host line, extract the hostname and store it in a scalar variable. Go to 1.
- If it is not an nfs line, go to 1
- Extract the share from the line.
- If there is no entry in your hash for that share, create one which is an arrayref with the current host as its only member. Go to 1.
- Append the current host to the existing arrayref in the hash value for the current share. Go to 1.