!/software/bin/perl use strict; use warnings ; while(<>){ my @line = split(/,/,$_); my @splice = splice(@line, 3,8); my $chr = shift @splice;#shifts the first element my %hash; $hash{$chr} = \@splice; foreach my $key (sort keys %hash){ print $key, "," , $hash{$key}[0] ,",", $hash{$key}[1], "\n"; } }