- or download this
$str =~ m/\A(.)/xms;
my $first_character = $1;
- or download this
$str =~ m/(.)\z/xms;
my $last_character = $1;
- or download this
$str =~ m/\A(.).*(.)\z/xms;
my $first_character = $1;
my $last_character = $2;
- or download this
$str =~ m/\A(.).*?(.?)\z/xms;
my $first_character = $1;
my $last_character = $2;
$last_character = $first_character if ! $last_character;