#1 $_ = $digit; s/.*(\d).*/$1/; # change everything to the captured digit $digit = $_; #2 $_ = $digit; m/(\d)/ && $digit = $1 # change $digit to be the captured digit #3 $digit =~ m/(\d)/ && $digit = $1 #4 $digit =~ s/.*(\d).*/$1/;