use strict; my $value; open IN, "data.file" or die "$!"; while () { chomp; if (/match the lines/) { $value++; } } close IN or warn "$!";