So now we know in a little more detail what you want your script to do. Unfortunately you still have not said in what way it is going wrong.
Here then are a few suggestions.
- Read, understand and implement at least the first 2 steps of the Basic Debugging Checklist. Do this now, before anything else.
- Test to see if you are actually looping over all files in the directory. At the very least print a count of all the files you have tested by the end of the script.
- Test your regex (which we now know is wrong). A simple perlish grep will do: perl -ne '/^module / and print' somedir/filename.v and then modify the regex until it extracts what you want.
- If you still can't get the required output then post back here stating precisely in what way your code fails and providing an SSCCE
Happy debugging!