Touch file only if it needs to be trimmed. More efficient file handling with single regular expression check