my $alias = " alias:"; my $palias = countP(); # refers to a sub process which gets a new alias number if ($line[4] =~ /\b$alias\b/) { # And strip the quotes from the notes for later. $line[4] =~ s["([^\x22]*)"][$1]; # And strip the quotes from the element0 for later. $line[0] =~ s["([^\x22]*)"][$1]; # Add element0 to end of element4 my $elzero = $line[0]; $line[4] = "\"$line[4].$elzero\""; # glue the elements together with tabs $lines = join "\t", @line; # replace the A alias with the a P alias & attach quotes $lines =~ s/$line[0]/\"$palias\"/; # increase the $palias by 1 $palias++; # remove carriage returns $lines =~ tr/\012\015//d; # print result to final output file print OUTFILE $lines; } else { # And strip the quotes from the notes for later. $line[4] =~ s["([^\x22]*)"][$1]; # And strip the quotes from the element0 for later. $line[0] =~ s["([^\x22]*)"][$1]; ## remove last value and store as $last ## # remove leading comma from $last $last =~ s/,//g; # Add element0 to end of element4 my $elzero = $line[0]; $line[4] = "\"$line[4].$alias.$last.$elzero\""; # the contents of the notes field is non empty # glue the elements together with tabs $lines = join "\t", @line; # replace the A alias with the a P alias & attach quotes $lines =~ s/$line[0]/\"$palias\"/; # increase the $palias by 1 $palias++; # remove carriage returns $lines =~ tr/\012\015//d; # print result to final output file print OUTFILE $lines; }