Ash Varma wrote:
Any hint on the J Smith and J Smith Thomas ??
Hmm, good point. I'm sure there are several methods, but the first which comes to mind is to do two replacements...
a. sort you list by the length(), processing longer names first b. 1st replacement replaces the all names with their unique id ... J Smith ___ J Smithers ___ J Smith Thomas ... becomes ... {{0001}} ___ {{0002}} ___ {{0003}} ... c. 2nd replacement puts the names back in ... {{0001}} ___ {{0002}} ___ {{0003}} ... becomes ... J Smith 00001 ___ J Smithers 0002 ___ J Smith Thomas 0003 ... For example: !/usr/bin/perl -w my @names = ( 'J Smith', 'J Smithers', 'J Smith Thomas' ); my $text = "... J Smith ___ J Smithers ___ J Smith Thomas ..."; my %id_to_name = (); my $idx = 0; foreach my $name ( sort { length($b) <=> length($a) } @names ) { my $playerid = sprintf "%04d", ++$idx; $id_to_name{$playerid} = $name; $text =~ s/\b$name\b/{{$playerid}}/g; }#foreach print "$text\n"; foreach my $id ( keys %id_to_name ) { $text =~ s/\{\{$id\}\}/$id_to_name{$id} $id/g; }#foreach print "$text\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>