{ my (%history, $histcount); # Should I initialise $histcount = 0 or is that "Cargo cult"? sub addHist { $history{ $_[0] } = $histcount++; } sub getHist { return = grep{ $history{ $_ } == ($histcount - $_[0]); } keys %history; } } ... # get $newvalue from somewhere addHist( $newvalue ); ... # deside we want the $n'th previous value my $last_nth = getHist( $n ); ...