# Sort the data by the number in the last part of the array @sorted = # return just the hash->key map { $_->[1] } # compare hash->key->value[3]'s sort { $a->[0] <=> $b->[0] } # anon array w/ hash->key->value[3], hash->key map { [ %test->{$_}->[3], $_ ] } # keys from hash keys %test; # rebuild array of pipe-seperated values, and put the line breaks back in $_.="|$test{$_}[0]|$test{$_}[1]|$test{$_}[2]|$test{$_}[3]\n" for(@sorted);