in reply to Matching first Perl statement.

Well, if you've got a particularly well constrained data set, then you might be able to achieve what you want without *too* much trouble. However, your example of using a string containing a semi-colon only touches on the complexity of the problem --- here's another:

my $x = do{ print "here's an embedded statement\n"; 42; };

And we can imagine all sorts of complications using other quote-like mechanisms like s//statement;statement;/e or s;;;ge ... But even if you can grok all the combinations of quote-like operators and embedded multi-statement terms, you still have a problem. As merlyn so aptly points out in this node, from which I'll extract (and modify) just one little tidbit:

$x = sin / 25 ; # /; die "Bang! I'm dead!"; $y = time / 25 ; # /; die "I'm only pretending!";

Where does the first statement end in each of these two lines? It isn't just that you have to ignore semi-colons inside of a match operation, you have to know whether you are even in a match operation at all. Thus, while the question as you pose it may *seem* like something far less complex than actually "parsing Perl" (I just want to recognize one leading, semi-colon terminated, arbitrary statement) it really isn't at all.

And we've competely ignored other things such as many statements without terminating semi-colons(in the same vein as Beatnik mentions):

while(<>){ if ($. == 1){ print "Now processing $ARGV ...\n" } print if /something/ .. /something else/ } continue { close ARGV if eof }

Which of course is rather contrived ... but still something to consider depending on what you are *really* trying to accomplish (although you did explicitly mention terminating semi-colons, so perhaps this isn't an issue for you).

On the other hand, I seem to recall that Simon Cozens (I think) was working on a Perl parser in Perl --- but I have no idea how far that went or what became of it.