# this is easy... # grab a string my $sa ='random,junk no,one,cares about(I,Want,This,stuff) but, (not,this) stuff which&might have-random characters'; # extract the string between the first set of ( and ) my ($sb) = $sa =~ m/\((.+?)\)/; # split the string on , my @ab = split(',',$sb); # join and butress the string with ^ my $sc = '^' . join('^',@ab) . '^';