Split the merge functions.
Restructure the perl script.