in reply to parsing a directory of log files.

It seems like there are so many problems with the OP code that the replies so far simply haven't been able to cover them all. There are still a couple whoppers that no one has pointed out yet. The first OP snippet starts out like this:
$dir= shift || '.'; opendir DIR, $dir or die "Can't open directory $dir: $!\n"; while ($file= readdir DIR) { next if $file=~/^\./; open (FH, ">", "$file") or die "Can't open file $file: $!\n"; my @file_lines=<FH>;
You truncate/open a file for output and then try to read from it? I hope you made a backup of the directory before you ran that script with $dir set to "." because the script would have obliterated all the data files. (Running it with some directory name in @ARGV would have saved your input data from oblivion, but wouldn't have gotten anything done.)

The second snippet avoids that problem, but still shares another problem with the first version: if $dir is set to something other than "." (i.e. via @ARGV), the open statement would need to be like this in order to do what you want:

open (FH, "$dir/$file") ...
Luckily, when you do it that way, it still works when $dir is set to "."

Put all that together with the other replies, and you should get pretty close to a working script.