Tk has limitations, but not this one;-).
In this case, you have to pass the widget into your sub. For example:
#!/usr/bin/perl
use Tk;
use strict;
use constant BUTTON_WIDTH => 20;
my $mw = new MainWindow(title => "demo");
my $button = $mw->Button(text => "color",
width => BUTTON_WIDTH)
->pack;
$mw->Button(text => "red",
width => BUTTON_WIDTH,
command => sub {change_color($button, "red")})
->pack;
$mw->Button(text => "green",
width => BUTTON_WIDTH,
command => sub {change_color($button, "green")})
->pack;
MainLoop;
sub change_color {
my ($widget, $color) = @_;
$widget->configure(background => $color);
}