my $equation = '979x + 87y - 8723z = 274320'; my @parts = ($equation =~ /^(?:(.*?)([xyz]))+/i);