#!/usr/bin/perl $text = "this is a line of textanother one"; @lines = $text =~ /<\!--begin-->(.*?)<\!--end-->/g; foreach (@lines) { print $_ . "\n"; }