If the IP address line always follows the hostname line, it may be easier to write the search logic if you read the file in reverse order, using File::ReadBackwards.
This is not an optical illusion, it just looks like one.
Comment on Re: Parsing multiple lines based on a given String