in reply to Re^2: Same problem replacing array index numbers
in thread Same problem replacing array index numbers

... producing something like this:
'xx @ra[1] y @ara[23] z @ra[1] aa @ara[23] b @ra[1] @ara[23]'
'xx @ra[1] y@ara[0] z @ra[1] aa@ara[2] b @ra[1] @ara[2]'

Good catch on the use of  //= versus  ||= in your code since the value of the generated random integer could, indeed, be zero leading to a redefinition on a subsequent encounter. I would quibble with
    $generated{$rand} = ();
however, since assigning the contents of an empty list to a scalar (i.e., undef) is very odd and likely to be confusing, it is much better, IMO, to assign 1 (or any true value) since that would slightly simplify the existence test to
    do { ... } while $generated{$rand};
(if, in fact, there is a requirement that the generated random integers be non-repeating).