foreach (@listA, @listB) { # or just one of the two, whatever # set $new_text to whatever you want s/.+?=/$new_text=/; }