Stop using $templine and $line, simply use $_. Print each $_ and set a debug print statement for when you hit your ABC match within the foreach loop.
Check out: foreach - Beginning Perl Tutorial, Control Structures
Comment on Re: Printing the variable makes the next match code work. Why?