my $offset = splice @cPosns, rand @cPosns, 1; #### my $offset = $cPosns[rand @cPosns]; #### while (1) { ... last; } #### ... #### push @cPosns, pos $zazb while $zazb =~ m{(?=c)}g; #### push @cPosns, $-[0] while $zazb =~ m{c}g; #### my $pos = -1; push @cPosns, $pos while ($pos = index($zazb, 'c', $pos+1)) >= 0; #### sub popnum3 { my ( $x, $y, $z ) = @_; # $_[3] is $zazb if ( $y == 0 ) { $aob[$x][0] = $initial * ( 1 + $z ); } else { my @cPosns; push @cPosns, $-[0] while $_[3] =~ m{c}g; if (@cPosns) { my $offset = $cPosns[rand @cPosns]; $aob[$x][$y] = $aob[$offset][ $y - 1 ] * ( 1 + $z ); } } return $aob[$x][$y]; }