# $text is the main text you want to process # $begin is the begin keyword # $end is the end keyword $text =~ s/\Q$begin\E.*\Q$end\E//s;