#!/usr/bin/perl use strict; use warnings; open FILEB, 'B.txt' or die "B: $!\n"; while () { my ($id,$add, $expire) = (split /\|/)[5,2,3]; open FILEA, 'A.txt' or die "A: $!\n"; open NEWA, '>A.txt.new' or die "New A: $!\n"; while () { if (/\|$id\|/) { my @rec = split /\|/; @rec[10, 11] = ($add, $expire): $_ = join ('|', @rec); } print NEWA, $_; } close FILEA; close NEWA: } rename 'A.txt.new', 'A.txt';