open FILE, "data.txt" or die $!; while(){ chomp; my ($uniq,$one,$two,) = split ','; # split the line into its fields $line_hash{$uniq} = qq($uniq $one $two); # use a _unique_ key value # describing the line to define # a hash key, and splice the # line to that key. } close FILE; # now sort by the (presumed) # numerical key, and print a test. for( sort { $a <=> $b } keys %line_hash ){ print "test: ",$line_hash{$_},$/ ; }