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"; }