my ($nobrackets) = (qr/[^\{^\}]+/); &replace(qr/\{$nobrackets\}/,'$1') #This line is changed below. sub replace{ s/$_[1]/$_[2]/g } #### my ($nobrackets) = (qr/[^\{^\}]+/); &replace(qr/\{$nobrackets\}/,"$1") #Using qq// instead of q//. sub replace{ s/$_[1]/$_[2]/g } #### #!/usr/bin/perl $_='{\selectlanguage{english} \textcolor{black}{\ \ 10.\ \ Three resistors connected in series each carry currents labeled }\textit{\textcolor{black}{I}}\textcolor{black}{\textsubscript{1}}\textcolor{black}{, }\textit{\textcolor{black}{I}}\textcolor{black}{\textsubscript{2}}\textcolor{black}{and}\textit{\textcolor{black}{I}}\textcolor{black}{\textsubscript{3}}\textcolor{black}{. Which of the following expresses the value of the total current }\textit{\textcolor{black}{I}}\textit{\textcolor{black}{\textsubscript{T}}}\textcolor{black}{in the system made up of the three resistors in series?}}.';; $nobrackets = qr/[^\{}]+/; my $pass = 0; while(++$pass <=2){ s/\\textsuperscript\{($nobrackets)\}/ startsuperscript $1 endsuperscript /g; s/\\textsubscript\{($nobrackets)\}/ startsubscript $1 endsubscript/g; s/\\textit\{($nobrackets)\}/ startitalic $1 enditalic/g; s/\\textcolor\{$nobrackets\}//g; s/\{($nobrackets)\}/($1)/g; print "Pass $pass:\n\n". qq{$_}."\n\n\n"; } #### Pass 1: {\selectlanguage(english) (\ \ 10.\ \ Three resistors connected in series each carry currents labeled )\textit{(I)}( startsubscript 1 endsubscript)(, )\textit{(I)}( startsubscript 2 endsubscript)(and)\textit{(I)}( startsubscript 3 endsubscript)(. Which of the following expresses the value of the total current )\textit{(I)}\textit{( startsubscript T endsubscript)}(in the system made up of the three resistors in series?)}. Pass 2: (\selectlanguage(english) (\ \ 10.\ \ Three resistors connected in series each carry currents labeled ) startitalic (I) enditalic( startsubscript 1 endsubscrip t)(, ) startitalic (I) enditalic( startsubscript 2 endsubscript)(and) startitalic (I) enditalic( startsubscript 3 endsubscript)(. Which of the following expresses the value of the total current ) startitalic (I) enditalic startitalic ( startsubscript T endsubscript) endital ic(in the system made up of the three resistors in series?)).