sub path_parts(@) { shift=~m((/[^/]*))g } sub limit_list($@) { $#_=-1+shift; @_ } #### my $orig_path = "/a/b/c/d/e/f"; my $trunc_path = join '', limit_list( 3, path_parts( $orig_path ) );