in reply to programs taking ages to exit

I suppose the number of lines in the file and the number of characters per line is rather high? If so, you're building a rather huge memory structure (very long list) in @lines, and it will take a while before memory deallocation is done and the program can exit.

Since this seems to be a very simple counting operation, you could consider reading one line at the time from the file, and, if necessary, even iterate over individual characters in the line.

Hope this helps, -gjb-