#build up the hash CF if (/CF/){ $hash{CF} = $tmp[1]; #say $hash{CF}; } #### #PROBLEM CODE check CF fields need to accommodate for multiple CF lines if (exists $hash{CF}) { $add = $hash{CF}; $line .= ",$add"; } #### ## #!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; my $HSSIN='D:\testproject\HSS-export.txt'; my $ofile = 'D:\testproject\HSS-output-withhash.txt'; open (INFILE, $HSSIN) or die "Can't open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; my %hash; my $count = 0; my $add; my $line; while () { chomp; next if /^/; next if /^/; if (/,".$hash{ODBIC}.",".$hash{ODBOC}.",".$hash{ODBROAM}.""; } else { #say OUTFILE "Update Command MSISDN=notSet,".$hash{ODBIC}.",".$hash{ODBOC}.""; $line = 'MSISDN=notSet'; } #PROBLEM CODE check CF fields need to accommodate for multiple CF lines if (exists $hash{CF}) { $add = $hash{CF}; $line .= ",$add"; } #check ODBIC field if (exists $hash{ODBIC}) { $add = $hash{ODBIC}; $line .= ",$add"; } else { $add = 'ODBICnotSet'; $line .= ",$add"; } #check ODBOC field if (exists $hash{ODBOC}) { $add = $hash{ODBOC}; $line .= ",$add"; } else { $add = 'ODBOC notSet'; $line .= ",$add"; } #check ODBROAM field if (exists $hash{ODBROAM}) { $add = $hash{ODBROAM}; $line .= ",$add"; } else { $add = 'ODBROAM notSet'; $line .= ",$add"; } #check hash for ODBOC->BAOC is not set set it to ODBOC->BAOCnotSet delete $hash{MSISDN}; delete $hash{ODBIC}; delete $hash{ODBOC}; delete $hash{ODBROAM}; delete $hash{CF}; #build up line say OUTFILE $line; } } close INFILE; close OUTFILE;