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=; # 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"; }