#!perl -w use strict; my $file = 'c:\autoexec.bat'; my $pattern = 'PATH'; my $seperator = '----------'; print "\n---find 1: using system\n"; my $t=system("find /c \"$pattern\" $file") ; print "->", $t, "<-\n"; print "\$t is the exit code\n"; print "\n---find 2: using `backticks`\n"; my $u=`find /c "$pattern" $file`; print "->", $u, "<-\n"; print "\$u is the output\n"; print "\n---find 3: 100% pure perl\n"; open(FILE, "< $file") or die("ERROR: failed to open file, $!"); # $count is initialized to prevent print from complaining # if no matches are found my $count=0; while( ) { ++$count if /$pattern/; } close(FILE) or die("ERROR: failed to close file, $!"); print "->", $count, "<-\n"; print "\$count is the match count\n"; print " -or, if you really want the same output format as find-\n"; print "$seperator $file: $count\n";