perl count lines with certain word int

Hi Guys

I have a text file that contains the message like this

/var/log/messages.all-20120401: Mar 26 12:12:23 brent kernel: NVRM: Xid (0003:00): 43, 0005 00009097 00000000 00000000 00001b0c 1000f010
/var/log/messages.all-20120401: Mar 27 20:42:40 brent kernel: NVRM: Xid (0003:00): 43, 0004 00009097 00000000 00000000 00001b0c 1000f010

how can i would like a way to count up the number of lines that has that error and then print that to the end of the file

thanks
A

perl -lane '$i++ if $_=~/PATTERN/; print $_;END{print $i}' input.txt > output.txt 

Can't you use grep?

thanks itkamaraj

thanks worked like a charm

is there a way i can work it into this little but of a scipt

sub pall_nvrm {
print "plese wait...This can take a while, all results will be outputed at the end\n";
print `pall -w -p "/u/ab/scripts/nvrm" |tee /tmp/nvrmoutput`;
<HERE>
}

ideally where it says <here>

Much thanks
Adam

open the file using the open method and read the data using while loop and check how many lines having the pattern. And in the end, you are write the count in the original file.