How to print a 2D array in Perl

Here is a simple function (subroutine) for printing 2-dimensional (2D) arrays in Perl

Function
sub print_2d { my @array_2d=@_; for(my $i = 0; $i <= $#array_2d; $i++){ for(my $j = 0; $j <= $#{$array_2d[$i]} ; $j++){ print "$array_2d[$i][$j] "; }	  print "\n"; } }

Example
my @data = ( [ 1, 5, 2, 19, 3, 7, '?'], [ 'one', 'five', 'two', 'nineteen', 'three', 'seven', '??' ] );
 * Code:

print_2d(@data); 1 5 2 19 3 7 ? one five two nineteen three seven ??
 * Output