#!/usr/bin/perl local $/ = undef; $_ = <>; 1 while s{ (^[^=]+) #should match the duplicated word [=] (.+) #should be the translation after the "=" \n \1 [=] (.+ \n) }{$1=$2, $3}xmig; print;