for( @s_dn ) { my $num = 1; # calculate the local num, somehow. s/NUM/$num/g; }