for (INIT; COND; INCR) { ... } #### #!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow::->new(); my @colours = qw{magenta red blue green darkred}; my $swatch = $mw->Label(-bg => 'black')->pack(-fill => 'x'); for my $i (0 .. 4) { $mw->Button( -bg => $colours[$i], -command => sub { colour_swatch(\$swatch, \@colours, \$i); }, )->pack(-fill => 'x'); } sub colour_swatch { my ($swatch_ref, $colours_ref, $i_ref) = @_; my $bg = ${$colours_ref}[$$i_ref]; $$swatch_ref->configure(-bg => $bg); return; } MainLoop;