#!/usr/bin/perl use strict; use warnings; my $output = ''; LINE: while ( my $line = ) { chomp $line; # if line ended with a '\', remove '\' and save line for later output if ( $line =~ s/\\$// ) { # clean indentation $line =~ s/^\s+/ /; # save line $output .= $line; next LINE; } # we have previous line(s) to consider? elsif ( length $output ) { # clean indentation $line =~ s/^\s+/ /; $line = $output . $line; $output = ''; } print $line, $/; } __DATA__ {FILE} sourcetag1 {NUMBER} 00000 11111 {SOURCE} source1 {KEYWORD} {AUTHOR} author1 staff1 {HEADLINE} DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\ STYLE AT A SPEED USUALLY ASSOCIATED WITH WARDROBE ITEMS. {FILE} sourcetag2 {NUMBER} 00002 {SOURCE} sourcenam2 {KEYWORD} {AUTHOR} author2 staff2 a\ b\ c