#!/usr/bin/perl -w use strict; my $cycle = initToggle( 3 ); for ( 1 .. 24 ) { print "$_\t" . &$cycle . "\n"; } sub initToggle { my $limit = shift; my $count = 0; my $bit = 0; unless ( $limit > 0 ) { die "initToggle() requires a positive argument\n" }; return sub { $bit ^= 1 if $count++ % $limit == 0; return $bit; } }