If the only trouble you are having is that it isn't writing to a file is that you are not printing to a filehandle. Look at the open() docs (perldoc -f open) and perlopentut to learn the different ways to open a file and write to it.
Cheers,
KM
Comment on RE: Apply regex to entire file, not just individual lines ?