m/[=]+Additional Notes[=]+.*?\n(.*)/s; #this (.*) will get all #to end of the $page #see below, ending [=]+ and /g is not #needed for this job #### #!/usr/bin/perl -w use strict; open (IN , '<', "awebpage.txt") or die; my @page = ; #this is like a "slurp" into a scalar my $page = join('',@page); #with undef record seperator my @comments = $page =~ m/[=]+Comments[=]+.*?\n(.*?)[=]+/gs; my $count =1; foreach (@comments) { print "COMMENT #$count is:\n$_"; $count++; } =file awebpage.txt is: A webpage. ===Comments=== This webpage contains information bla bla bla =Section 2= Some more text here. whatever ===Comments=== Some other comments here. =Another section= =Aditional Notes= =Comments= some more comments and notes here =Notes= More notes here. =cut =****prints:**** COMMENT #1 is: This webpage contains information bla bla bla COMMENT #2 is: Some other comments here. COMMENT #3 is: some more comments and notes here =cut