in reply to Code Issue after Upgrading the perl from 5.14.4 to 5.22.3

please use below in your code first
use strict; use warnings;
Also it looks like $mapattach variable is not declared with the right scope and causing the issue or data in the input file gets change for different runs.