After looking at your suggestion, I'm not sure if it would work. So if you could, please explain. My questions follow.
What I wanted to do was search on %hosts{$ip} and replace with %hosts{$a} where IP is the IP address of the host and $a is the hostname given by nslookup. I couldn't tell if that is exactly what your s///eg process was doing.
Thanks,
Monger