in reply to Reading particular line which repeats itself many times in text

If you want to use $k instead of $_, you have to use it everywhere:
if ($k =~ /BEGIN/ .. $k =~ /END/)