open(HOSTS, '/etc/hosts') || die("Out of cucumber error\n"); my %hosts; while() { s/#.*//; next unless /(\S+)\s+(.*)/; my $host = $1; push @{$hosts{$host}}, split(/\s+/, $2); } use Data::Dumper; print Dumper(\%hosts);