It might improve things a bit if you rearrange your if statements, you don't need to check ($A + $B == 2...) for each line of the input file, as you know that $B can only change when you've matched RTINSECONDS so you could do this instead :-
if ($line =~ /TITLE=(.*)/) {
$title=$1;
}
elsif
($line =~ /RTINSECONDS=(.*)/) {
$RT=$1;
if ($title && grep {$_ eq $TI} @IDS) {
$IDrtPairs{$TI}=$RT;
$title = undef;
}
}
As already mentioned it will be better to use a hash, so you should do that too :)
The example input data looks like TITLE & RTINSECONDS are always at the beginning of the line so you could anchor your regexs too, so it can reject non matching lines quicker. i.e. /^TITLE=(.*)/