use strict; use warnings; use Test::More no_plan => 1; my @input = ( [ 'a' .. 'f' ], [ 'g' .. 'l' ], [ 'm' .. 'r' ], [ 's' .. 'x' ], ); my @expected = split '', 'abcdeflrxwvutsmghijkqpon'; my @try; while (@input) { push @try, @{shift @input}; push @try, pop @$_ for @input; @input = reverse @input; @$_ = reverse @$_ for @input; } print "@expected\n"; print "@try\n"; is_deeply( \@try, \@expected );