use List::Util qw{ shuffle }; # ... for my $row (shuffle(1 .. $row_size)) { for my $column (shuffle(1 .. $column_size)) { ... } }