# How to catch the part after the last slash in Perl?

Hi,
How can I catch the last part of a string which is after the last slash (back slash or forward slah) in Perl?

Example:

/some/path/in/here


Return:

here


or

\some\path\in\here


Return:

here


or

\some\path/in/here


Return:

here


or

/some/path\in\here


Return:

here

###### Who is Participating?

Commented:
($last) =$str =~ m{([^/\\]*)$}; 0 Commented: Assuming the string you want to extract the last part from is in$str, this will do it:
$last = (split m{[/\\]},$str)[-1];

Or this:
if ($str =~ m{^.*[/\\](.*)$}) {
$last =$1;
}

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.