use strict; use warnings; my $file = do {local $/, }; #read the file from $file =~ s/\n\;/\;/g; #replace newline followed by semicolon with semicolon print $file; output: -------- asdfadfasdf asfadfasdf;asfadfasdfas fasfasdfas;asdfasdfasd asdfasdfasfd __DATA__ asdfadfasdf asfadfasdf ;asfadfasdfas fasfasdfas ;asdfasdfasd asdfasdfasfd