Two infinite classes of perfect codes in metrically regular graphs