sub onTick { our $x; my $changed; # Initialize and associate $x with some external value foreach (@kabluther) { do { # these two lines must be a block - do together, or not at all. $x += $_->getSkookiness(); $changed++; } # if clause can go here I think, if needed } if ($changed) { $_->ticked() for @listeners; } return $x; }