in reply to Search PCL file

What results are you getting, and what results do you expect? Perhaps also a description of what you code is doing may help you help yourself find the error....

sub get { # Is this assignment necessary? $data_file = $file ; # 2 argument form of open(), non-lexical file handle, # and using stronger binding "||" instead of "or". # Could be better as: # open(my $dat, "<", $data_file) or die(...); open(DAT, $data_file) || die("Could not open file!"); @raw_data=<DAT>; # Careful here, will also catch "11 of", "21 of", ... $search="1 of"; foreach $line (@raw_data){ if ($line =~ /$search/){ # You are counting the number of times you match, # not the number after the match. Also, it does # not look like this is ever initialized. $count++ ; } } print "Packs returned: $count\n"; }

If I understand your post correctly, you want instead to match the (watch for the hint here) number after your search string.

If your intent is actually to count the number of times that you see your search string, you can do that more efficiently* using scalar and grep.

* - for some definition of "more efficient".

--MidLifeXis