$expr =~ s(\[((?:[A-Z/]+)\s){4,4})\]){ my $match = $_; $match =~ s([/\s])(_)g; $match; }ge;