in reply to Extract portion of string based on string separator
File::Spec is likely to be a more portable and less fussy way of managing path manipulations:
use strict; use warnings; use File::Spec::Functions qw(splitdir catdir splitpath); my $path = "/a/b/c/d/e/f"; my @foo = splitdir ($path); my $subpath = catdir (@foo[1..3]); # Note that the "volume" is blank s +o skip that print "Sub path = $subpath\n";
Prints:
Sub path = a\b\c
|
|---|