use List::Util 'shuffle'; my @bag = shuffle qw( A B C D E ); my @embargoed = pop @bag; while ( 1 ) { my $time = ( localtime )[ 0 ]; # seconds sleep 1; if ( $time >= 55 ) { push @embargoed, pop @bag; push @bag, shift @embargoed if @embargoed > 2; @bag = shuffle @bag; sleep 5; } print "$time @embargoed\n"; }