my @sorted_array = map { $_->{line} } # extract the lines again sort { # do the sorting $a->{ts} <=> $b->{ts} || $a->{letter} cmp $b->{letter} } map { # build a data-structure that we can sort on my ($ts, $letter) = split / /; { line => $_, ts => $ts, letter => $letter } } @array_to_sort;