my %hash1; open my $IN, "file1.txt" or die $!; my $header = <$IN>; ## use if the file has a header otherwise leave it while(<$IN>){ chomp $_; my @line = split(',',$_); ## split the line to get the sample name and its values $hash1{$line[0]} = 1; ## if your first column is a sample name or change it accordingly } close($IN);