in reply to newbie hasher

If you expect your input to be 'dirty', then regular expressions might serve you better:

use strict; use Data::Dumper; my %hosts; while (<DATA>) { chomp; next if /^#/; $hosts{$1} = $2 if /^(\w+)\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/; warn "Garbage at line $. of DATA: $_\n" unless $1 and $2; } print Dumper(%hosts); 1; __DATA__ host1 1.13.10.116 #comment host2 21.90.30.31 #blah blah blah host3 56.87.1.10 host4 13.16.17 #The following hosts are on network B host5 57.98.18.10 #yadda yadda yadda host6 106.10.3.12

Splits would be more efficient if you expect the input to be clean, though.

Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"