while( ) { s[\s(\d+)\d\K\s(?=(\d+)\d\s)]{ print "$1:$2"; $1 + 1 == $2 ? "\n" : ' ' }ge; print; }