There is a
gotcha lurking .
I don't believe that the the contents of <head>has to be in any specific order.
Why worry: just capture the Title: (<title>.*</title>) and forget the Style (if the same stylesheet is used)
Replace the <head> with your boilerplate that has a \1 where the <title> goes. THEN use Link stylesheets to reestablish control