my (%history, $histcount); # Should I initialise $histcount = 0 or is that "Cargo cult"? sub addHist { my ($hashref, $histcount, $new ) = @_; # Naming our parameters makes things clearer # validate $hashref->{ $new } = $histcount++; } sub getHist { my ($hashref, $histcount, $new ) = @_; #validate return = grep{ $hashref->{ $_ } == ($histcount - $n); } keys %history; }