You could cut the piece out, then use it to cut a matching piece from a spare piece or from a closest, etc. Then, cut a piece from a heavy paper bag that is a couple of inches larger on every side than the area to be replaced. Fit this in the hole so that the edges go under the carpet and glue it around the edges. This now creates a backing for the carpet to be installed on so that it will move with the carpet and not be glued to the subfloor. Next you simply glue the carpet in place unto its new backing.