in reply to Merging two files

It's usually much faster and easier to do the whole work in Perl, if possible. Using awk, grep, head, tac, etc. is most often not needed. You should probably start from a simpler task and build your script in steps.

Also, if you want us to help you, you need to provide everything we need to reproduce your situation. Without the *log files, your question doesn't belong among SSCCE.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,