$constant = '$$'; $line_count =0; while (){ if($constant ne "") { if($_ =~ m/^($constant)/) { $line_count++; } } }