in reply to reading the wrong input file out of 2 opened file

Additionally, from open, use the three arg open:

open(my $fh, "<", "input.txt") or die "Can't open < input.txt: $!";

Also: http://modernperlbooks.com/mt/2010/04/three-arg-open-migrating-to-modern-perl.html.