in reply to Re^4: Reorganizing the content of a file
in thread Reorganizing the content of a file

Hmm, a requirements change :)

#!/usr/bin/perl # https://perlmonks.org/?node_id=1227383 use strict; use warnings; local $_ = join '', <DATA>; for my $id ( /^(\d+)/gm ) { print /^$id,.*,(\S+)/m; $id = $1, print ',', /^$id,.*,(\S+)/m while /^$id,(\d+)/m; print "\n"; } __DATA__ 5,#,A 1,5,B 4,5,C 2,4,D