in reply to Getting the shortest match?

You might not be able to do this for all regexes, and like Abigail-II says, its a costly operation, but in your particular case, you could do something like this:
my $str = "abc def ghi abc 123 junk"; my $short; while ($str =~ /abc.*?123/g) { $short = $& if ! defined $short or length($&) < length($short); pos($str) = $-[0]+1; } print "$short\n";