package ButtonJar; sub new { my $self = shift; $self = {}; return bless $self; } sub add { # add a button to the "jar" my $self = shift; my $but = shift; $self -> { $but -> id() } = $but; sub remove { # remove a button my $self = shift; my $but = shift; delete $self -> { $but -> id() }; } sub getall ( my $self = shift; return keys %$self; # to return the $widget -> id # or could return values %$self or just %$self # depending on how you want to reference your buttons } 1;