in reply to Regex::Common balanced does not seem to work

You should always use strict and warnings. You get the following error when using those:
Variable "$RE" is not imported at 1063912.pl line 20. Global symbol "$RE" requires explicit package name at 1063912.pl line +20. Execution of 1063912.pl aborted due to compilation errors.
The fix is to change ${RE} to $RE