my %result; # preusume @ARGV is loaded with the changeNN files in the right order while (<>) { if (/^L\|(\S+)\s+(.*)/) { $result{$1} = $2; } elsif (/^E\|(\S+)/) { $result{$1} = undef; } else { warn "I don't understand: $_"; } } for (sort keys %result) { my $value = $result{$_}; if (defined $value) { # last thing was a change: print "L|$_ $value\n"; } else { # last thing was a delete: print "E|$_\n"; } }