my $s = (length($str) < $index ? substr($str, $index, 1) : '' # or undef, or die, or ... );