Logic gates are the fundamental building blocks in any digital data-processing circuit. We propose a new method to implement a NAND logic operation controlled from a long distance. To realize it we consider two types of Gaussian pulses: the control beam and the signal beam. The signal beam propagates first through an electro-optic modulator and then through a nonlinear waveguide, whereas the control beam propagates directly through the optical fiber. Controlling the applied voltage of the electro-optic modulator, we can change the phase relation between the pulses. Hence a NAND switching operation can be realized at a very long distance in the optical fiber.