my $file = join '', @file; # put it all in a single scalar if ($file =~ m/(?:what you want to find.*){6}/) { print "'what you want to find' was in the file at least 6 times.\n"; }