This code.... # First, get the subset cluster number. our ($cluster1, $other1) = split(/\s/, $line2, 2); chomp $other1; my @A2 = split(/\s/, $other1); chomp @A2; is just this... my ($cluster1, @A2) = split(/\s+/,$line2); This line does not do what you think it does... chomp $c; # remove trailing white space in $c ('ugly stuff')