- Works with single-character strings. Both $f and $l are set to that character.
- For zero-length strings, both $f and $l are undefined.
- For zero-length strings, the whole expression returns false in scalar context.
my ($f,$l) = /^(.).*(?<=(.))/s;
- Works with single-character strings. Both $f and $l are set to that character.
- For zero-length strings, both $f and $l are set to the zero-length string.
- Readable.
my $f = substr($_, 0, 1);
my $l = substr($_, -1, 1);