in reply to concatenating elements of an array in twos

If the situation is that these things are sequential as in your example data, this is a common pattern that does not require the storage of the output array.
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $line = <DATA>; #get started with first line chomp $line; my ($prev_sidpart,$prev_rest) = split /\|/, $line; while (my $line = <DATA>) { chomp $line; my ($cur_sidpart,$cur_rest) = split /\|/, $line; if ($prev_sidpart eq $cur_sidpart) { $prev_rest .= " $cur_rest"; } else { print "$prev_sidpart|$prev_rest\n"; ($prev_sidpart,$prev_rest) = ($cur_sidpart,$cur_rest); } } print "$prev_sidpart|$prev_rest\n"; #last record =prints: sid 1|FLPSDFFPS LLWFHISCL WIRTPPAYR YVNVNMGLK sid 2|FLPSDFFPS LLWFHISCL FLPSDFFPS ELMNLATWV sid 7|FLPSDFFPS ATVELLSFL VWIRTPPAY LLSFLPSDF sid 9|VWIRTPPAY LLDTASALY FGRETVLEY PSDFFPSVR =cut __DATA__ sid 1|FLPSDFFPS LLWFHISCL sid 1|WIRTPPAYR YVNVNMGLK sid 2|FLPSDFFPS LLWFHISCL sid 2|FLPSDFFPS ELMNLATWV sid 7|FLPSDFFPS ATVELLSFL sid 7|VWIRTPPAY LLSFLPSDF sid 9|VWIRTPPAY LLDTASALY sid 9|FGRETVLEY PSDFFPSVR