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