in reply to
Getting a funny newline that was not there before
I was going to guess that you might have windows line-endings in your hostfile2 - which would also give you problems - but I think moritz has probably nailed it with his comment.
Replace the four instances in getNetworkInfo where you globally undef $/ to do so with just local effect:
# undef $/; # global effect!
local $/ = undef; # local effect
It also appears that you're not running under strict or warnings (unless you've snipped that from your post). You really should look into that.