However, when I try this code, it doesn't remove anything. I tried to open the input file in a text editor and saw white spaces in front and after the string. When I tried in a dos box "type input.txt" I noticed all the white spaces got replaced by "á" signs.

I'm guessing I'll need to use another expression, the problem is I don't know what to match for. How can I discover that hidden character that seems like a white space, but isn't one after all?

The type command is telling you that the file contains non-ASCII characters. Before attempting to get rid of them, you really should figure out where they come from. Two possibilities come to mind. The first is that the file is not intended to be an ASCII file. In that case you must either tell perl the encoding or read the file in binary and convert it yourself. A second possibility is that you are reading past the end of the file. This is very unlikely if the file is being read on the same machine that created it. The problem can be hard to track down unless you know (for sure) the last few characters of some file or its exact length. If neither of these are the cause, I strongly recommend that you keep looking for it. Blindly removing data that you do not understand is going to cause problems in the future. Good Luck, Bill