in reply to remove the part of the string that is after the second to last '/'

There are lots of ways to do it, and this thread will likely fill up with them. I can't help noticing that what you're looking for resembles the unix command "dirname", however.
chomp($str = `dirname $str`);
Yes, it's silly and not portable. I'm just covering a base here. :-)

The dirname method in File::Basename would be a good choice if you are in fact manipulating directory paths. This module is reasonably platform independent and part of the core Perl distribution.

use File::Basename; my $dir = dirname($filename);
Do "perldoc File::Basename" for more information.