How to substitute brackets in the beginning of string in perl?

Hi,

I have a string like this user can specify different query sets that is why "or" is mentioned:


$string="[[:<:]](";

or

$string="[[:<:]]((";

or

$string="[[:<:]](((";

or

$string="[[:>:]](((((";

What i have to do is substitute these brackets in the beginning.

I tried like this:


if($string=~/\[\[:<:\]\]\(/)
{
  $string=~s/\[\[:<:\]\]\(/\(\[\[:<:\]\]/g;
}
elsif($string=~/[[:<:]]\(\(/)
{
   #same here
}
elsif($string=~/[[:<:]]\(\(\(/)
{
  #same here
}
elsif($string=~/[[:<:]]\(\(\(\(/)
{
  #same here
}
elsif($string=~/[[:<:]]\(\(\(\(\(/)
{
  #same here
}

If statement i can use but i will be not be sure how many brackets will be there to substitute in the beginning?

I have to avoid this if loop!!

The output should be like this.

$string="\([[:<:]]";

or

$string="\(\([[:<:]]";

or

$string="\(\(\([[:<:]]";

etc like this all these different string examples are based on the users query sets that is why i just mentioned or such that user can give either like first string ( [[:<:]]\( ) or like second string ( [[:<:]]\(\( ).

How can i put or substitute brackets in the beginning of the sting?

Any ideas???

Regards
Vanitha

maybe:

@strings = ("[[:<:]](", "[[:<:]]((", "[[:<:]](((", "[[:>:]](((((");

for (@strings) {
    s/^([^(]+)([(]+)$/$2$1/;
    print "$_\n";
}