- or download this
my $equation = '979x + 87y - 8723z = 274320';
my $vars = 'xyz';
my $operators = qr/[-+*\/%=]/;
my @parts = $equation =~ /([^\s$vars]+|[$vars]|$operators)/g;
- or download this
perl -d
DB<1> $equation = '979x + 87y - 8723z = 274320'
...
7 'z'
8 '='
9 274320
- or download this
my @parts = $equation =~ /([^xyz]+(?=[xyz])|[xyz])/g;
- or download this
perl -d
DB<1> $_='979x + 87y - 8723z = 274320'
...
3 'y'
4 ' - 8723'
5 'z'