package test; sub new { ## something } sub InitDialog { #something something my $book = $frame->Notebook->pack ; foreach my $type qw(pageone pagetwo pagethree) { $page = $book->add("$type",-label => $type); $text = $page->Scrolled('Text',-scrollbars => 'e', -width => ($item_width+15), -background => '#efefef' )->pack; $text->tagConfigure('item', %attr_item); &build($text); } while(my ($k,$v) = each(%is_selected)) { print "$k -> $v \n"; } } sub build { # your same build subrtn # only difference is the passed $text argument is held # in a variable. The rest is same # And $text is passed to move as well } sub move { ## Same code &build($text); }