How to rewrite the output of $content inside a pane template?
Look in your panels module the function template_preprocess_panels_pane() you can use this.

http://www.drupalcontrib.org/api/drupal/contributions%21panels%21panels.module/function/template_preprocess_panels_pane/7

http://www.drupalcontrib.org/api/drupal/contributions!panels!panels.module/function/template_preprocess_panels_pane/8