sub with_srand { srand(shift); $_[0]->(@_[1..$#_]); srand(); } # later with_srand $known_thing, sub { ... }, args...;