It's a bit hard to tell exactly what you want to
do (please use <code> tags when you enter something
that needs to retain its format), but here is a
guess that might set you on your way. It slurps the entire
file up at once (which may not work if it is really
huge), then removes single newlines embedded in the pattern and adds a
leading newline. Naturally you may want
to generalize this to work for other patterns:
perl -e "undef $/;$_=<>;s/G\n?5\n?7/\nG57/g;print;" yourfile.txt