while($row = $sth->fetchrow_arrayref) { $Replacement[12]=$row->[0]; #etc.... #then in the loop still... $Kine=~s/FLF(\d\d)/$Replacement[$1]/ge;