in reply to open fails to open file when filename read from STDIN

I think you need to chomp $file too.

in any case you need to check for errors from open:

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

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!