A quick fix would be to change .+ to .+?.
You can read more about this issue in perldoc perlre.
In reply to Re: Matching HTML Comments by matija in thread Matching HTML Comments by stuaxo