my %context; ... $button->bind('' => sub{chg_btn(\%context, @_}); #### sub sensorHandler { my ($context, ...) @_; $context->{sensorOn} = $data !~ /(?## sub chg_btn { my ($context, ...) = @_; $btn1->configure(-background => "green", -foreground => "black") if !$context->{sensorOn}; }