SV *tmp = sv_2mortal(newSVsv(foo)); if (av_store(av, ix, tmp)) SvREFCNT_inc(tmp);