in reply to how to stop the file

you could use the last function , which immediately breaks out of the loop. Keep in mind that (Quoting from the documentation) "last cannot be used to exit a block which returns a value such as eval {}, sub {} or do {}, and should not be used to exit a grep() or map() operation"