$ perl -le '$line = shift; @fish = split /\s*fish\s*/, $line; print for @fish' 'One fish two fish red fish blue fish' One two red blue