map { [Button => $_, -command => sub { replace($_) }] } @menu_items #### sub replace{ my $chosen="Label of button user clicked on"; $t->insert('sel.first',"$chosen"); $t->delete('sel.first','sel.last'); $t->tagConfigure("rp",-foreground=>"black"); my $r=$t->search(-forwards,"$chosen",'end'); $t->tagAdd("rp","$r","$r wordend"); } 1; #### $m = $top->Menu(-tearoff => 0,font => "{arial} 12 {bold}", -menuitems => [ [Button => "$opt1", -command => \&replace1], [Button => "$opt2", -command => \&replace2], [Button => "$opt3", -command => \&replace3], ] ); sub replace1{ my $chosen1=$menu_items[0]; $t->insert('sel.first',"$chosen1"); $t->delete('sel.first','sel.last'); $t->tagConfigure("rp1",-foreground=>"black"); my $r1=$t->search(-forwards,"$chosen1",'end'); $t->tagAdd("rp1","$r1","$r1 wordend"); } 1; sub replace2{ my $chosen2=$menu_items[1]; ... } 1; sub replace3{ my $chosen3=$menu_items[2]; ... } 1; #### sub replace{ my $chosen="$menu_items[$_]"; print "\nThe selected word:"; print "\n$chosen"; } 1;