#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::ExecuteCommand; my $global = 'foobar'; my $mw = MainWindow->new; my $ec_dir = $mw->ExecuteCommand( -command => "echo $global; dir; sleep 5; dir;", -entryWidth => 50, -height => 10, -label => '', -text => 'Execute dir ', )->pack; my $ec_date = $mw->ExecuteCommand( -command => "echo $global; date; sleep 5; date;", -entryWidth => 50, -height => 10, -label => '', -text => 'Execute date ', )->pack; my $dir_but = $mw->Button( -text => 'Execute dir', -background => 'hotpink', -command => sub{ $ec_dir->execute_command })->pack; my $date_but = $mw->Button( -text => 'Execute date', -background => 'lightgreen', -command => sub{ $ec_date->execute_command })->pack; MainLoop;