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