#value of the maximal id ever delivered our $maxid = 0; #hash of name-id pairs our %ids; sub get_my_id { my ($name) = @_; if (!(exists $ids{$name})) { $ids{$name} = $maxid++; } return $ids{$name}; }