SV *make_aoa_c( int n_rows, int n_cols ) { int i, j; char *foo = "foo"; AV *table = newAV(); AV *row; int len = strlen(foo); av_extend(table, n_rows-1); for ( i = 0; i < n_rows; ++i ) { row = newAV(); av_extend(row, n_cols-1); for ( j = 0; j < n_cols; ++j ) { av_push( row, newSVpv( foo, len ) ); // or newSVpvn(...) } av_push( table, newRV_noinc( row ) ); } return newRV_noinc( table ); }