removing blank lines after all lines start with specific string

HI,
Is there any way to remove from a file, all blank lines that exist after line start with specific string?

for example:

Remove all blank lines after lines start with XXX1

`
XXX1bla bla bla

hjshfgdfg
gdfsgdsgdf
gsdfgd

XXX1 blu bluu blu

dfjgljfd
gfdgds

`

will be:

`
XXX1bla bla bla
hjshfgdfg
gdfsgdsgdf
gsdfgd

XXX1 blu bluu blu
dfjgljfd
gfdgds

`

you can write shell script for that and put that code in playbook.

- replace:
        path: my_file
        regexp: '(XXX1.*)$\s+'
        replace: '\1'