# print the whole thing with refs faster than for # but you are destroying the AoA (matrix) while ( defined ( my $aref = shift @$matrix ) ) { say $wfh "@$aref"; }