use Tie::Toggle; tie my $toggle, 'Tie::Toggle'; my @color = qw(black white); print "$color[$toggle]\n" for 1..10;