my ($nobrackets) = (qr/[^\{^\}]+/); &replace(qr/\{$nobrackets\}/,"$1") #Using qq// instead of q//. sub replace{ s/$_[1]/$_[2]/g }