#this while loop isn't right, but I don't know what is...; while ($tbltext =~ //cg) { $counter = 1; #reset the counter; $tbltext =~ s/()/ ++$counter == $nth #is this the nth cell? ? "${1}newtext" #if yes, add "newtext" : $1 #otherwise, leave it /ge; $tbltext =~ /<\/tr>/cg; #find the end of the row } #exit the loop