local $/; open my $fh, '<', 'file.txt' or die $!; my $txt = <$fh>; $txt =~ s/\n\|/ /g; for ( split '\n', $txt ) { # process each line }