in reply to How can group these strings

If your intention was just to group this strings, then chomp in a perl one-liner could do the job.
Case (a):

perl -pe "chomp;" text.txt
this is equalvalent to:
LINE: while (defined($_ = <ARGV>)) { chomp $_; } continue { die "-p destination: $!\n" unless print $_; }

Case (b):

perl -ne "chomp;print" text.txt

which is equalvalent to:
LINE: while (defined($_ = <ARGV>)) { chomp $_; print $_; }

Hope this helpss -:)