my @sorted_aoh = sort { (map /^doc(\d+)/ ? 0+$1 : (), keys(%$a))[0] <=> (map /^doc(\d+)/ ? 0+$1 : (), keys(%$b))[0] } @aoh;