my $file = do { local $/; <> }; 1 while $file =~ s/^(([ ]+)(?![ ])[^\n]+)\n\2(?![ ])/$1/m; print($file);