Anchoring the Match
Strip whitespace from start and end:
s/^\s+|\s+$//g;
Extract heading text from POD document:
my @headings = m/^=head\d\s+(.*)$/mg;