my $cndiea = 0; foreach my $del ( 0 .. $chntot ) { if ( substr( $aod[$yb], $del, 1 ) eq 'y' ) { $cndiea++; } } while ( $cndiea < $incrsdel ) { my $xda = int rand( $chntot + 1 ); if ( substr( $aod[$yb], $xda, 1 ) eq 'a' ) { substr $aod[$yb], $xda, 1, 'y'; $cndiea++; last; } }