foreach (@fields) { m/%%(\w+?)%%.*%%(\w+?)%%/; push @matches, $1, $2; }