/foo(?!.*foo)/ #### s/(?<=foo)/,/g; # Without lookbehind: s/foo/foo,/g or s/(foo)/$1,/g #### s/(?<=look)(?=ahead)/-/g; #### /foo # Match starting at foo ( # Capture (?: # Complex expression: (?!baz) # make sure we're not at the beginning of baz . # accept any character )* # any number of times ) # End capture bar # and ending at bar /x; #### s/(?<=, # after a comma, (?! # but not matching (?<=\d,) # digit-comma before, AND (?=\d) # digit afterward ) )/ /gx; # substitute a space #### s/(?<=, # after a comma, but either (?: (?## print "$1\n" while /(?=(.*))/g;