in reply to newbie hasher

While I don't doubt that your file looks like that, it's not a regular hosts file. In /etc/hosts, each line has an IP followed by a name (and optionally more names), whereas you have a name followed by an IP. /etc/hosts can also have comments in it. To deal with a traditional /etc/hosts file ...
open(HOSTS, '/etc/hosts') || die("Out of cucumber error\n"); my %hosts; while(<HOSTS>) { s/#.*//; next unless /(\S+)\s+(.*)/; my $host = $1; push @{$hosts{$host}}, split(/\s+/, $2); } use Data::Dumper; print Dumper(\%hosts);