in reply to String replace depending on diff
If these are Verilog files, you can use Verilog-Perl to parse the 2 files to get a list of all port names and directions.
Read Writeup Formatting Tips and update your post.
In Section
Seekers of Perl Wisdom