Match the nth longest possible string in Perl
问题 The pattern matching quantifiers of a Perl regular expression are "greedy" (they match the longest possible string). To force the match to be "ungreedy", a ? can be appended to the pattern quantifier (*, +). Here is an example: #!/usr/bin/perl $string="111s11111s"; #-- greedy match $string =~ /^(.*)s/; print "$1\n"; # prints 111s11111 #-- ungreedy match $string =~ /^(.*?)s/; print "$1\n"; # prints 111 But how one can find the second, third and .. possible string match in Perl? Make a simple