while ((my $this = shift @sorted) and @sorted) ...