s/\\\[.*?\]\\//g; # get rid of what you don't want first @wanted = (/\[(.*?)\]/g); # then get what you want