perl -nle "/TABLE;(.*)/?($t=$1):/COLUMN;([^;]*)/&&print(qq{$t.$1})" file1.txt #### syntax error at -e line 1, near "(=" Execution of -e aborted due to compilation errors.