in reply to This regexp made simpler

Another way to go using rubasov's data set plus a completely illegal line (ZA). The below is more "wordy" than other solutions, but I think what it does and how it does it is clear. If for example, RESULT=" " should be disallowed, there is a clear place to do that modification.
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; my $result = is_match($_); defined($result) ? print "$_:\tRESULT=\"$result\"\n" : print "$_:\tRESULT=NO MATCH\n"; } sub is_match { my $term = shift; my $inner = ($term =~ m/^A(.*)Z$/)[0]; return undef if (!defined($inner)); return $inner if $inner eq ""; return $inner if $inner =~ m/^\s/; return undef; } =prints: AZ: RESULT="" AZZ: RESULT=NO MATCH A SOMETHING Z: RESULT=" SOMETHING " ASOMETHINGZ: RESULT=NO MATCH A Z: RESULT=" " A ZZ: RESULT=" Z" AAZZ: RESULT=NO MATCH AA ZZ: RESULT=NO MATCH ZA: RESULT=NO MATCH =cut __DATA__ AZ AZZ A SOMETHING Z ASOMETHINGZ A Z A ZZ AAZZ AA ZZ ZA
Update: I looked at the OP's spec again and it appears that this tweaking of is_match() would be better?:
sub is_match { my $term = shift; my $inner = ($term =~ m/^A(.*)Z$/)[0]; return undef if (!defined($inner)); return undef if $inner eq ""; return $inner if $inner =~ m/^\s+\S/; return undef; } prints:..... AZ: RESULT=NO MATCH AZZ: RESULT=NO MATCH A SOMETHING Z: RESULT=" SOMETHING " ASOMETHINGZ: RESULT=NO MATCH A Z: RESULT=NO MATCH A ZZ: RESULT=" Z" AAZZ: RESULT=NO MATCH AA ZZ: RESULT=NO MATCH ZA: RESULT=NO MATCH