while () { next if /^\s*#/ ; # skip comments chomp; my ($key, $value) = split (/\s+/, $_); $hosts{$key} = $value; # here was your mistake }