in reply to Regular expression query

The simplest solution is to always parse the PEM and store it in a variable. Like this you only need to print that variable out if you have a match.