<?xml version="1.0" encoding="windows-1252"?>
<node id="1015544" title="Re: Replacing values in an array" created="2013-01-26 18:26:10" updated="2013-01-26 18:26:10">
<type id="11">
note</type>
<author id="176576">
eyepopslikeamosquito</author>
<data>
<field name="doctext">
&lt;P&gt;
When dealing with duplicates in Perl, you should normally use a hash
(&lt;I&gt;perldoc -q duplicate&lt;/I&gt;).
My solution (written before seeing [toolic]'s) is essentially the
same as his, though I
excluded the check for "M" since all your test data contains "M".
&lt;CODE&gt;
use strict;
use warnings;
use Data::Dumper;

my @array = ("M94202", "M94150", "M94297", "M94150", "M94161", "M94161", "M94162");

my %seen;
my $z = 1;
foreach my $item (@array) {
    if (exists $seen{$item}) {
        $item = $seen{$item};
    }
    else {
        $seen{$item} = $z;
        $item = $z;
        $z += 2;
    }
}
print Dumper \@array;
print "\n";
&lt;/CODE&gt;
&lt;/P&gt;
</field>
<field name="root_node">
1015541</field>
<field name="parent_node">
1015541</field>
</data>
</node>
