sub make_counter { my $count = shift; sub { ++$count } } $mw->Button(-text => "count", -command => &make_counter(0)});