#!/usr/bin/perl use strict; use warnings; my @list = qw( one two three one one two_2 two_2 two two_2 two two_3 two one ); @list = make_unique( @list ); print "@list\n"; sub make_unique { my (%seen, $try); map { my $n = $seen{$_}; $n++ while $seen{$try = $n ? $_ . "_$n" : $_}++; $try } @_; }