my $dynamic_hash = {0 => "job",1=> "state",2 =>"dependencies",3=>"result"}; &build_layout($init_hash); sub build_layout { ## samething what u have sent foreach my $itemkey (sort keys %$dynamic_hash) { my $btn=$text->Checkbutton(%attr_item,'-activebackground'=>'#ff7f7f' ); my $up=$text->Button(-text=>'Up',%attr_btn, -command => [\&moveup,${$dynamic_hash}{$itemkey} ); my $down=$text->Button(-text=>'Down',%attr_btn,)-command => [\&movedown,${$dynamic_hash}{$itemkey}; ..... ..... $text->insert('1.0',sprintf('%-'.$item_width.'s',${$dynamic_hash}{$itemkey})); } sub moveup { my $text = shift ### not able to proceed here } sub movedown { }