If you don't absolutely need to use a regex, useconsider using Perl's Text::Balanced to remove the parenthesis.
use Text::Balanced qw(extract_bracketed);
my ($extracted, $remainder, $prefix) = extract_bracketed( $filename, '()', '[^(]*' );
{ no warnings 'uninitialized';
$filename = (defined $prefix or defined $remainder)
? $prefix . $remainder
: $extracted;
}
You may be thinking, "Why do all this when a regex does the trick in one line?"
$filename =~ s/\([^}]*\)//;
Text::Balanced handles nested parenthesis. So $filename = 'foo_(bar(baz)buz)).foo'
will be extracted properly. The regex based solutions offered here will fail on this string. The one will stop at the first closing paren, and the other will eat them all.
$filename =~ s/([^}]*)//;
# returns 'foo_buz)).foo'
$filename =~ s/(.)//;
# returns 'foo.foo'
# text balanced example returns 'foo_).foo'
If either of the regex behaviors is acceptable, use a regex--but document the limitations and the assumptions being made.