perl -le '$_ = "abcdefg"; while (/(...)/g) { print $1; pos($_) -= length($1); pos($_)++ }'