$tmp=(get the file contents); $tmp=~s/\r//g; $tmp="\n$tmp\n"; ($n,$v)=[got from somewhere, same as list items] ($ctr)=[got from somewhere else] ($rctr)=[count of replacements made] ## attempt 1 if ($tmp=~/^$n\t$v$/) { $tmp=~s/^$n\t$v$/$n\t$v\t$ctr/; $rctr++; } else { ....