#!/usr/bin/perl use strict; my $string = "something and something else or this thing here"; my @out = split(\s(AND|OR)\s/i,$string); $string = ""; foreach my $i(@out) { if($i =~ /\s?(AND|OR)\s?/i) { my $tmp = uc($1); $string .= " $tmp"; } else { $i =~ s/$i/ tools.description LIKE "\%$i%"/o; $string .= $i; } } print "$string\n"; #### tools.description LIKE "%Something%" ANDsometing else ORthis thing here #### Something and something else or this thing here