#!/usr/bin/perl -n0
use 5.010;
for$x(g,o,p,r){say;s/$x/ /&&redo}