Q:

Perl first pair match?

I have data like these:
a{b}cde
a{b}c{d}e

I want to spilt the string into three parts:

string before first {} pair
string in first {} pair
rest

here is my code:
if(/(.*){(.*)}(.*)/){
    print "$1\t$2\t$3\n";  # ===> a{b}c   d       e
}

but it's not work for a{b}c{d}e
I want a   b    c{d}e instead of a{b}c   d       e

A:

Making .* non-greedy (.*?) will do the trick:
#!/usr/bin/perl
use strict;
use warnings;

while (my $line = <DATA>) {
    if($line =~ m/(.*?){(.*?)}(.*)/){
    print "$1\t$2\t$3\n";
    }
}

__DATA__
a{b}cde
a{b}c{d}e

