use v5.16; my @sorted = (sub { return @_ unless @_ > 1; my $pivot = splice(@_, int(@_/2), 1); my (@small, @big); push @{ $_ < $pivot ? \@small : \@big }, $_ for @_; return (__SUB__->(@small), $pivot, __SUB__->(@big)) })->(@unsorted);