## OP specified 'last
' tag, 
## so assume there can be more than one 
..
block ## find all
 blocks, using non-greedy .*? and also
## get \n in the case where the html ends with a newline and no 
## anchor to non-capturing match for closing
or end of string my @pre = ( $VAR1 =~ m{
(.*?\n?)(?:
|$)}isg ); ## we want the last one my $new_output = pop @pre;