Does each element have a line to itself or is the data multiline? As in, if we read line say 123 from file A, will line 123 in file B be the correct line to do the processing with?
If that is the case, then you could just read both files a line at a time, and use a simple regex to get the value out of the <elem> wrapper;
my ($a,$b,$value_a,$value_b);
while (1) {
$a = <A>;
$b = <B>;
if ($a =~ m/<elem>(.*?)</elem>/)
{
$value_a = $1;
}
if ($b =~ m/<elem>(.*?)</elem>/)
{
$value_b = $1;
}
last if !defined $value_a || !defined $value_b;
print data_transform($value_a, $value_b);
}
I'm sure better perl adepts than me could write it better/faster, but I think that would work if the files have a line for line concurrency.