in reply to Rexgrep

There are ways to do this using a regular expression. For example:
if ($img =~ m#.*/(.*)#) { $name = $1; } else { # didn't match! }
This works because the first .* is greedy and matches up until the last "/" in $img; then we keep the rest.

However, solutions using substr and index (or rindex) are often faster than regexps in cases like this, and this is no exception, at least with the regexp above:

use Benchmark; timethese(1000000, { 'regexp' => sub { my($file) = $img =~ m#.*/(.*)# }, 'substr' => sub { my $file = substr $img, rindex($img, '/') + 1 } });
gives
Benchmark: timing 1000000 iterations of regexp, substr... regexp: 11 secs (11.18 usr 0.00 sys = 11.18 cpu) substr: 4 secs ( 5.67 usr 0.00 sys = 5.67 cpu)