open(HOSTFILE,"<$hostfile"); foreach (){ if($_ =~ m/^#/){next;} if($_ =~ m/^\s$/){next;} # Insert this line to split by whitespace my @lineParts = split (/\s+/, $_); # push (@hostcontents,$_); # Push [0] first column (ip), or use [1] for second column (hostname) push (@hostcontents,$lineParts[0]); } close(HOSTFILE);