my $last_digit = ''; if ($string =~ /(\d){1}$/) { $last_digit = $1; }