in reply to random elements with fixed totals

No need to loop. Set up the list with the appropriate numbers of 1s and 0s and then shuffle it.

use List::Util qw[shuffle]; $m = 65; $n = 100; @list = ( (1) x $m, (0) x ( $n - $m ) ); @list = shuffle @list;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!