Please add <code> tags around your data, you had to go through a preview page to post this and so you should have noticed it was badly formed.
As to your problem:
- open file one
- while there are records in the file
- if the line contains a string followed by one of your required strings
- add the initial string to a hash of acceptable gene strings.
- open file 2
- while there are records in the file
- if the line begins with a > and the rest of the line exists in your hash
- write this line to a temp file
- read the next line and add it to the temp file also (I think, not sure of what you have specified)
- rename the temp file to file2 if you wish to overwrite the original version.
Code that up and come back with any specific issues you are having.
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."