http://www.perlmonks.org?node_id=138702

vladb has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to use a single pattern match to match a single Perl statement (delimited with a ;)?

Although looks rather trivial, I struggled to come up with anything workable for these cases:
myfunc $x eq "foo;text";foobar';';$x++; # matching first Perl statement.. # should return: # myfunc $x eq "foo;text"; # # not: # myfunc $x eq "foo;";foobar'; # # or something else...
My first (shameful) attempt was this pattern: m/([`'"])*[^\1]*;[^\1]*\1;/. However, it didn't work (for some obvious reasons ;).

I've also looked at Text::Balanced. But couldn't figure which of its methods I had to use in order to accomplish what I wanted. Basically, the idea is to find first statement delimited by a ';' while also avoiding any occurance of ';' inside a pair of quotes.

Thanks in advance ;-)

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith