use Tk; $bgcolor = 'yellow'; #you only use a variable 'reference' with specific attributes $w = MainWindow->new(-background => $bgcolor, -title => 'Retrieving text'); $w->Button(-text => 'Retrieve', -command => sub { getthetext() })->pack(-side => left); $w->Button(-text => 'Clear', -command => sub { clearthetext() })->pack(-side => right); #note the difference between variable and variable 'reference' $w->Label(-text => 'a label', -background => $bgcolor, -textvariable => \$labeltext)->pack(); $w->Button(-text => 'Quit', -command => sub { exit() })->pack(-side => bottom); #scrollbar is optional and on the 'east' side $text = $w->Scrolled(Text, -scrollbars => 'oe', -width => 40, -height => 10)->pack(-side => bottom); MainLoop(); sub getthetext { #note the strange indices used to refer to text in Text widget $thetext = $text->get("1.0","end"); @words = split(/\W+/,$thetext); $labeltext = $#words+1 . " words"; } sub clearthetext { #note the strange indices used to refer to text in Text widget $text->delete("1.0","end"); }