Perl (Scripting) - Trailing forward slash

by
Jeremy Canfield |
Updated: May 06 2020
| Perl (Scripting) articles
Let's say you have a string that contains multiple forward slashes, like this.
$foo = "/path/to/some/directory";
The following regular expression will remove everything after the last forward slash.
$foo =~ s|\/[^/]+$||;
Printing $foo . . .
print $foo;
. . . should return the following.
/path/to/some
Did you find this article helpful?
If so, consider buying me a coffee over at