in reply to problem with array

Do you only care about the printed output?

my $acc = "New Group:"; while (<IN>) { chomp(); $acc .= " $1" if m|<ref\s+id="([^"]+)">|; print "$acc\n" and $acc = "New Group:" if m|</end>|; }