Acyclovir works by inhibiting the replication of viral DNA. It achieves this by incorporating itself into the viral DNA chain, thereby preventing the virus from multiplying and spreading. This mechanism is crucial for controlling HSV infections in neonates, as it helps to limit the extent of the infection and reduces the risk of severe complications.