use Tk; use strict; use warnings; my $mw = MainWindow->new(); for my $index (0 .. 10) { $mw->Button(-text=>"Button $index", -command => sub {print $index})->pack(); } MainLoop; #### use Tk; use strict; use warnings; my $mw = MainWindow->new(); for (0 .. 10) { $mw->Button(-text=>"Button $_", -command => sub {print $_})->pack(); } MainLoop;