use Tk; my $FILTER_IS_ON = 0; my $top = new MainWindow(); my $b = $top->Button(-text=>$FILTER_IS_ON ? 'turn off' : 'turn on', -command => \&turn)->pack(); MainLoop(); sub turn { $FILTER_IS_ON = $FILTER_IS_ON ? 0 : 1; $b->configure(-text=> $FILTER_IS_ON ? 'turn off' : 'turn on'); }