http://www.perlmonks.org?node_id=978016


in reply to how to remove everything before last slash in perl?

Your regex:

$output =~ s{.*(/)}{$1}

...says to match any number of characters followed by a slash, then replace the whole match with a slash. As a result, if there is a match there is going to be a slash in the output. There's actually no point in even specifying $1 because your substitution is the same as:

s{.*/}{/}

Here are some other solutions:

1.

use strict; use warnings; use 5.010; use File::Basename; my @paths = ( "y:/home/lib/directory/book", "y:/home/lib/directory/book_manager", "y:/home/lib/directory/piano_book", ); my @results = map basename($_), @paths; say "@results"; --output:-- book book_manager piano_book

2.

@results = map { (split '/', $_)[-1] } @paths;