in reply to parsing a terrible /etc/hosts

On ignoring comments: one way would be to bin them altogether. If $line contains your line from the hosts file, you could

$line =~ s/#.*//;

remove the hash and any character following it.