for (@words) { while(/(.)/g) { $flip = $_; $flip =~ s/$1\./\.$1/ge; # flip match + next char print $flip; } }