open FILE, "file.txt"; my $count; while () { $count++ unless /\S+/; } close FILE; print $count;