# ... my @not_recent = grep !defined( $recent_ids{ $_ } ), @ids; my $idno; { use integer; $idno = (1+$#not_recent) * rand(); } # ...