my $string = ' hi hello @begin i want this to extract yes i want @end asas x x x x x zxzxax hi hello hi hellooo @begin i want this to extract yes i want @end ...'; while ($string =~ m/\@begin([\w\W]*?)\@end/g) { print "match: $1\n"; }