my @button = defined $idx ? ( OK => sub { &edit_entry($idx,$legentry); $tl->destroy; }, Apply => [\&edit_entry, $idx, $legentry], Delete => sub { &delete_entry($idx); $tl->destroy; }, Cancel => [$tl => 'destroy'], ) : ( OK => sub { &add_entry($legentry); $tl->destroy; }, Apply => [\&add_entry, $legentry], Cancel => [$tl => 'destroy'], ); for($tl->Frame) { $_->pack; while(my ($text, $command) = splice @button, 0, 2) { $_->Button(-text => $text, -command => $command) ->pack(-side => 'left'); } }