$def =~ s/ (^\.\w+\s) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := some whitespace (.+) ## $4 := Some anything ( ## $5 ^ ## The start of string/line select ## The word 'select' \. ## A literal '.' . ## Any single character $ ## The end of the line/string ) /$2$5/x; ## put back just first word and the 'select' etc