#!/usr/bin/perl use warnings; use strict; $\ = $/; $_ = reverse "(a+b)*c"; # or some longer sequence s/\)([^()]+)\(/]$1[/g; print scalar reverse y/][/)(/r; __END__ $ perl test.pl Missing right curly or square bracket at test.pl line 10, within string syntax error at test.pl line 10, at EOF Execution of test.pl aborted due to compilation errors.