use Modern::Perl; use Test::More; main(); sub main { my @foo = (1 .. 8); my @bar = reverseswap( @foo ); is $bar[0], 2, 'swapped the first one'; is $bar[1], 1, '... with the second'; is $bar[2], 4, '... and so on'; is $bar[3], 3, '... and so on'; is $bar[4], 6, '... and so on'; is $bar[5], 5, '... and so on'; is $bar[6], 8, '... and so on'; is $bar[7], 7, '... and so on'; done_testing; } sub reverseswap { my @array; push @array, reverse splice @_, 0, 2 while @_; return @array; }