Most of the time, the argument to glob() won’t be tied, so we don’t
need to copy it. So only copy it if it is gmagical.
dVAR;
OP *result;
dSP;
- /* make a copy of the pattern, to ensure that magic is called once
- * and only once */
- TOPm1s = sv_2mortal(newSVsv(TOPm1s));
+ /* make a copy of the pattern if it is gmagical, to ensure that magic
+ * is called once and only once */
+ if (SvGMAGICAL(TOPm1s)) TOPm1s = sv_2mortal(newSVsv(TOPm1s));
tryAMAGICunTARGET(iter_amg, -1, (PL_op->op_flags & OPf_SPECIAL));