$line =~ s/^ #strip, from the beginning of the string, myword\s+ #myword, followed by whitespace \S+ #followed by non-whitespace (?:,\s*\S+)* #followed by any number of comma, optional whitespace, non-whitespace //x; # update: two slashes are needed here