Perl array fixes v3.0.x

A copy from #722, but for v3.0.x, there were conflicts.