|go ahead... be a heretic|
Note: it often helps you and us if you reduce your sample code to just demonstrate the bug. Most likely in the process you will solve the problem, but even if you don't you will understand it better. In either case you will remember the lesson better at the end of the day.
Your sample could have reduced to:
where I expected:
I know what I mean. Why don't you? has a few other related tips that may help in the future.
Why no use strict by the way? Especially puzzling as there is a use warnings.
Note too that the 3 parameter open is much preferred over the two parameter open (see open) for lucidity and security.
looks wrong! Do you really intend to assign $target1 to $cols? Note that the if is (effectively) testing the contents of $target1, not equality of $target1 and $cols.
DWIM is Perl's answer to Gödel