Why are you using cat? Wouldn't
$line_count = `wc -l $filename`
work just as well?
Of course one could argue that you could
just do the entire thing in Perl rather than using system calls;
I might argue that, for instance. Here's a
version of wc in Perl; you could extract the bits you need.
Or you could do something like this:
sub lines_in_file {
my $f = shift;
open FH, $f or die "Can't open $f: $!";
1 while <FH>;
$.;
}
This would take care of your "space-in-filename" problem as
well, since Perl won't care; it's only a problem when you pass
it off to the shell like that.
You can use this like:
my $line_count = lines_in_file($filename);