while () { my ($key,@fileData) = split /\|/; chomp @fileData; $test{$key} = \@fileData; } #to while () { chomp; my ($key,@fileData) = split /\|/; $test{$key} = \@fileData; } #### foreach my $key (keys %test) { push (@sorted, "$key|$test{$key}->[0]|$test{$key}->[1]|$test{$key}->[2]|$test{$key}->[3]"); } #to foreach my $key (keys %test) { push @sorted, (join '|', ($key,@{$test{$key}}); } #### open(TEST, ">test.txt") || die "File couldn't be opened for writing: $!"; foreach my $key (sort keys %test) { print TEST (join '|', ($key,@{$test{$key}}); print TEST "\n"; } close(TEST); #### foreach my $key (sort keys %test) { #to foreach my $key (sort { $test{$a}[-1] <=> $test{$b}[-1] } keys %test) {