x y a b 1 2 3 4 5 6 7 x y 1 2 a b 3 4 5 6 7 -- recurse x y 1 2 3 4 a b 5 6 7 -- recurse x y 1 2 3 4 5 6 a b 7 x y 1 2 3 4 5 6 7 b a -- first swap on this recusion level x y 1 2 3 4 5 6 7 b a -- restore y's position x y 1 2 3 4 5 6 7 a b -- second swap and recurse $y == @$ary now, so stop.