my @video_ids = sort { $tmp{$a}{published} cmp $tmp{$b}{published} || $tmp{$a}{title} cmp $tmp{$b}{title} } @$ids; @video_ids = reverse @video_ids if $new_first;