in reply to joining lines

If it will always be a constant number of fields per line, you could do something like this:

while(<>){ chomp; my @line = split /\|/; while( @line < 4 ){ $_ .= <>; chomp; @line = split /\|/; } if( @line > 4){ warn "Found line with too many elements"; } print join "|", @line; print "\n"; }