in reply to Re: open file and write the content into another file
in thread open file and write the content into another file

Variable interpolation happens only inside double quotes. Change this ... to ...

And perhaps even better, change to the three-argument form of open:
    open my $fh, '<', $filename or die "Can't open '$filename': $!";
(no need to string-interpolate  $filename in  open call, quoting  $filename in error message makes all whitespace explicit).