And
$arr[-1] is the last element of
@arr, no matter how many elements you ended up with. You could also use a regex match:
Code:
$str =~ m%([^/]*)$%; print $1
This searches for characters adjacent to end of line ($) which are not slashes [^/] -- the * wildcard will match as many as possible.