Couple of comments on the code:
- Variable names like numvar2 and OUTFILE4 don't tell the reader what's stored in them or what the purpose of the filehandle is. Better use descriptive names.
- You're scanning through all lines of portnameok every time you're reading a line from iftoportchop. That's probably unnecessarily expensive. Can you read in iftoportchop once and store everything you need in a data structure instead or is iftoportchop prohibitively large?
- The next command doesn't really accomplish anything in this case. Did you mean to use last instead?