#!/usr/bin/perl use strict; use warnings; my $file = './test.txt'; my $content; { local $/; open(my $fh,'<',$file) or die $!; $content = <$fh>; close $fh; } $content =~ s/#String:.*?sa\d{3}s\d{2}\n?//sg; print $content;