my $coco = do { my @colors = qw[ pink maroon green OliveDrab4 PaleVioletRed3 RosyBrown2 PeachPuff4 WhiteSmoke azure3 chartreuse1 coral3 gold1 firebrick4 linen salmon4 tomato2 ]; my $ix = 0; my $size = int(@colors) ; sub { my $mod = $ix % $size; my $cix = $mod; warn "$ix $cix $colors[ $cix ]\n"; $ix++; return $colors[ $cix ]; }; }; $coco->() for 1 .. 100;