my $file = "/path/to/file/and/filename"; open(LOG,"$file") or die; my $match_count; while() { my (@matches) = $_ =~ m/(127\.0\.0\.1)/g; $match_count += scalar(@matches); } print $match_count , "\n";