@dirs = split qr{[\\/]}, $path; $file = pop @dirs unless -d $path; #### $path = '/' . join '/', @dirs, ($file // '');