in reply to Perl script to Parse a file for a string

As every body suggest, I think regex will help you a lot. Here is short version perlrequick and the complete one perlre.

A few months ago I implemented something similar, here is what I did. I hope it helps for me worked just fine based on my needs. I have included some information to help you understand the process, just in case that something is a bit more complicated just let me know I will try to explain more.

#!/usr/bin/perl use warnings; # it warns about undefined values use strict; # it's a lexical scoped declaration use Data::Dumper; use constant ARGUMENTS => scalar 3; $| = 1; #flushing output my $filename; my $Counting = 0; my $Characters = 0; my $source = $ARGV[0]; my $patern = $ARGV[1]; my $target = $ARGV[2]; my $elements; my $value; my $lines; my @found; my @word; #my $path_source = "/path/".$source.""; #my $path_destination = "/path/".$target.""; open(READ, ,"<", $source) or die "Can not open ".$source.": $!\n"; # < read mode open(WRITE, ,">", $target) or die "Can not open ".$target.": $!\n"; # > write mode if (@ARGV > ARGUMENTS) { print "Too many argument inputs\nCorrect syntax ".$source." ".$pat +ern." name of the file to store the data.\n"; } elsif (@ARGV < ARGUMENTS) { print "Need more argument inputs\nCorrect syntax ".$source." ".$pa +tern." name of the file to store the data.\n"; } else { while ($lines = <READ>) { chomp ($lines); # chomp avoid \n on last field @word = split ((/\s+/), $lines); #\s+ = 1 or more white-space char +acters # \d+ matches one or more integer numbers foreach $value (@word) { if ($value eq $patern) { push (@found, $value); print "I have found one matching pattern: $value\n"; } } } $elements = scalar(@found); print "I found number of occurrences: ".$elements."\n"; print WRITE "I found pattern: $patern, number of occurrences: $ele +ments\n"; } close (READ) or die "READ did not close: $!\n"; close (WRITE) or die "WRITE did not close: $!\n"; $| = 1; #flushing output

You can modified it to meet your needs in sub loop or print error conditions etc.

Seeking for Perl wisdom...on the process...not there...yet!