#! perl -slw use strict; use List::Util qw[ shuffle ]; our $N ||= 10; my @people = map{ $_ . 'a', $_ . 'b' } 1 .. $N; my $iters = 1; ## Just for testing my @indices = shuffle 0 .. $#people; ++$iters, @indices = shuffle 0 .. $#people while grep{ $indices[ $_ + 1] & 1 ## If the upper item is odd ? $indices[ $_ ] +1 == $indices[ $_ + 1 ] ## the lower shouldn't be -1 : $indices[ $_ ] == $indices[ $_ + 1 ] +1 ## vice versa } 0 .. $#people/2; @people = @people[ @indices ]; ## shuffle the real data print "Took $iters iterations"; ## How many tries? print "@people[ $_, $_+1 ]" for 0 .. $#people/2 if ; ## Allows ^C