my $cgi = new CGI; my $subject = $cgi->param('subject'); my @b; { local $/="***Begin Here***\n"; open INF, "< /full/path/to/postall.txt" or die $!; @b = grep { chomp; # remove "***Begin Here***\n", then # remove marker and return true to grep if match s/^\*\*\*Begin \Q$subject\E//; } ; close INF or die $!; } # lines go by for (@b) { s/\n/\n/g; } print @b;