in reply to Search strings stored in array into files of a directory

Hi tejas1991 Another monk has already pointed out that you should have use strict; use warnings; at the top of your script. Here are another couple of suggestions.

It's good to comment your code, but because you're using up to 8-space indentation, and then placing the comments at the end of the line, it makes the script hard to read. You should put the comments on the line above. It's also not usually necessary to comment a line that is very simple and clear. Get into the habit of writing clear, simple code that you can read, and save the comments for more confusing parts of your program. Also, I recommend 2-char indentation, but certainly no more than 4, and most importantly, be consistent!

Use the three-argument form of open() and assign your filehandle to a non-global variable. See perlopentut.

Mostly avoid using || as it can bite you if you forget the parentheses: prefer or. See Logical or and Exclusive Or.

You don't need to double-quote a variable unless it needs to be interpolated when used. I.e., not when passing it to open(). See an old tutorial on this site.

chomp() your lines as you read them to remove new-line characters that will mess you up later. (You do some of this later in the script). See chomp.

It's good to learn how to work manually in Perl including things like listing files in a directory, but you should use basic modules for basic tasks. For example, your current script reads all the files in the directory including the special files . and .. which you probably don't want. Use File::Find or one of its friendlier friends such as File::Find::Rule instead and you'll save time and protect yourself from typos and other simple errors.

If you want to get each element of an array, use for @array or foreach my $element ( @array ).

OK coffee's ready, good luck, have a great Monday :-)

The way forward always starts with a minimal test.