in reply to What happens with empty $1 in regular expressions? (was: Regular Expression Question)

You can get rid of the second conditional. If the regex succeeds, $1 will be set to the captured element. If the regex fails, $1 will be undefined or whatever was in it previously.
my $sss = "M9"; if ($sss =~ m/(\d+)/){ print "Value Matched on: $1\n"; # prints Value Matched on: 9 } $sss = "Mm"; if ($sss =~ m/(\d+)/){ print "Value Matched on: $1\n"; # if statement is not entered } print "\$1 holds $1!\n";

The generally accepted wisdom is to use conditionals exclusively if you're capturing things. You could also add an else clause, undefining $1.