sub renderAttribute { my ($self, $xml) = @_; ... # code to create the entry widget for this piece of XML my $entry = $parentFrame->Entry(-textvariable => \$attributeText, -validatecommand => $self->createValidateCallback($attributeXML))->pack(); ... } sub createValidateCallback { my ($self, $xmlObj) = @_; return sub { # these params are how Tk will call this callback my ($newValue, $deltaText, $origValue, $deltaIndex, $deltaType) = @_; return $self->updateXML($xmlObj, $newValue); }; }