Strange, I only get the use of uninitialized value, and the
elements of the array are printed. The uninitialized value
comes from the fact you let $cnt become scalar @array.
But the last element of the array has index scalar (@array) - 1.
Use either for (my $cnt = 0; $cnt < @array; $cnt) { ... }, or