use strict; use warnings; my @strings = ( "____\n", "__ __\n", "__X __\n", "__Z__\n", "__\n__\n", "__^__\n", "_____\n", "________\n", ); foreach my $string ( @strings ) { print "<<$string>>\n"; if( $string =~ m/__(\S+?)__/ ) { print "\tNon-Greedy -- Match: (($1)).\n"; } else { print "\tNon-Greedy -- No Match.\n"; } if( $string =~ m/__(\S+)__/ ) { print "\tGreedy -- Match: [[$1]].\n"; } else { print "\tGreedy -- No Match.\n"; } }