If I read your post correctly, you want to find strings that match without finding stuff where that string is a substring of a longer string. To do this, you need to know how the line will be delimited in the file. You seem to indicate that it will be quoted with double quotes. In which case, using if ($row =~ /\"out.h\"$/ ) {...} should be working.
This appears to be what you are doing with
if ($row=~ /$m$names[$k]$m$/g))
if $m = '"' and $names$k = out.h. You don't need the /g option BTW. as there can only be one string at the end of the line ($) and you appear to capturing/printing the whole line anyway. You could also hardcode the "'s into the regex as shown above unless the delimiter can vary?
One thing that comes to mind is that if this is C or C++ source code and you are looking for lines that include header files or a specific header file, the #include "some.h"; has a semi:colon on the end and you would need to include this into your regex before the $.
If you are still having trouble, try including a little more of the code (showing where @names and $M are being setup along with a (small) sample datafile on which your code is failing and you'll get better answers.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
In reply to Re: Exact string match
by BrowserUk
in thread Exact string match
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |