in reply to substition in multiple lines

This probably doesn't help, but your regex works for me when I run it. Can you give more details as to how it's failing for you?
$line = "this is a test [[ this is a test ] ]"; $line =~ s/\[\[[^\]]*\]\s*\]/***FOO***/sg; print "Line: '$line'\n";
prints
Line: 'this is a test ***FOO***'
You also don't need the /m modifier in this case, since you're not using ^ or $ in your regex.