in reply to Matching a range of lines using a regex (the .. and ... operators)

You will have to do some sort of buffering of your input data. Your program read line-by-line and will not handle (by design) tags spanning multiple lines.

#!/usr/bin/perl -w use strict; my $text = do { local $/; <DATA> }; # read entire file print $text; $text =~ s/<B.*?ird>[^=+]*[=+]*\B//sg; # remove unwanted stuff print $text; __DATA__ (Example 1) I have the following lines: This is some text....<Bluebird>.. MBAAAEgAAAQAB blaah,blaah =+=+=+=+=+=+=+=+=+=+=+ (Example 2) but sometimes it looks like this: This is some text....<B luebird>..MBAAAEgAAAQAoBA AAQKAREDSCETRTBDFS blaah,blaah =+=+=+=+=+=+=+=+=+=+=+

And the output is as expected:
(Example 1) I have the following lines: This is some text.... (Example 2) but sometimes it looks like this: This is some text....