#from chr 2 to right before first space or to the end of $str #if no space is found # - ^.{2} = skip past first two characters # - \S = not whitespace, \s=whitespace # - (\S*) captures zero or more non-whitespace characters # - ($str =~ /^.{2}(\S*)\s/) is a list containing one string, # i.e. ($1) where $1=what was captured by (\S*) printf "substr(2, first ' ' or end): %s\n", ($str =~ /^.{2}(\S*)/); #from chr 2 to lessor of 5 character or first space #\S = not whitespace, \s=whitespace printf "substr(2, first ' ' or 5 chars): %s\n" , ($str =~ /^.{2}(\S{0,5})/); #from chr 3 to first X or end of $str printf "substr(3, first 'X' or end): %s\n" , ($str =~ /^.{3}([^X]*)/); #from chr 3 to lessor of first X or 5 chars printf "substr(3, first 'X' or 5 chars): %s\n" , ($str =~ /^.{3}([^X]{0,5})/); #from chr 3 to first occurance of two or more A's or to the end if #no doubled A's are found printf "substr(3,two or more A's or end): %s\n" , ($str =~ /^.{3}(.*?)(AA|$)/); #from chr 10 to lessor of 5 chars or first of run of 2 or more A's printf "substr(10,two or more A's or 5 chars): %s\n" , ($str =~ /^.{10}((?:[^A]|A(?!A)){0,5})/); #from chr 10 to lessor of 5 chars or first of run of 2 or more X's printf "substr(10,two or more X's or 5 chars): %s\n" , ($str =~ /^.{10}((?:[^X]|X(?!X)){0,5})/); #from chr 5 to first occurance of two or more X's or to the end if #no doubled A's are found printf "substr(3,two or more X's or end): %s\n" , ($str =~ /^.{3}(.*?)(?:XX|$)/); #outputs substr(2, first ' ' or end): XCDEFDGHIXTAAGRAAAAAA substr(2, first ' ' or 5 chars): XCDEF substr(3, first 'X' or end): CDEFDGHI substr(3, first 'X' or 5 chars): CDEFD substr(3,two or more A's or end): CDEFDGHIXT substr(10,two or more A's or 5 chars): IXT substr(10,two or more X's or 5 chars): IXTAA substr(3,two or more X's or end): CDEFDGHIXTAAGRAAAAAA theEnd