#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $term = "( foo ) AND ( bar OR boo ) NOT ( far )"; # This regex isn't right my (@matches) = ( $term =~ /( )?(AND|OR|NOT)?( )?(\((.*)\))?/g ); # Testing print $_,"\n" foreach (@matches); # My plan was pull out all the parens and their contents # + the preceeding condition # then modify those result to put into a hash in the same # structure as below. # This is what the results should come out as my %tests = (); $tests{1} = { condition => "", terms => [ "foo" ] }; $tests{2} = { condition => "AND", terms => [ "bar", "OR foo" ] }; $tests{3} = { condition => "NOT", terms => [ "far" ] }; print Dumper(\%tests); exit;