foreach (@lines) { chomp; if (/^\s*\|\|/) { # is a comment s/}/endbrace/g; s/{/openbrace/g; s/^\s*||/"; } }