in reply to Regexing a block of text in between patterns

I'm having a little trouble understanding your goals here, so correct me if the following code does not address your issue. I am reading this as you wish to locate all occurrences of [Sidenote: *] and extract the unique text, displaying it surrounded by <div> tags. A (re)read of perlretut might be useful for you, but the following code does what I describe above.

use strict; use warnings; my $text = "C:\\letters.txt"; my @letters; open IN, '<', $text or die "Can't open $text"; @letters = <IN>; close(IN); chomp @letters; foreach my $indiv_note (@letters) { if ($indiv_note =~ /\[Sidenote\:\s(.*?)\]/) { print "<div>$1</div>\n"; } }

Note that the way I have written this, sidenotes cannot cross line boundaries, though doing this would be fairly trivial. Also note that if you want to include [ and ] in your posts, you should use html entities, i.e. &#91; and &#93;