in reply to Regex - one and only one / at beginning and end of file path

First, your single line doesn't work because you can't string two separate s/// together like that.   What you wrote was
$directory =~ s<^/*></> . </*$></>;
Turning on warnings would've helped here.

cchampion fixed his RE so I can't explain why it doesn't work, cause now it does.

What I've been able to make work is something that recognizes the _middle_ of your string, not either end.   This is a translation out of Perl Cookbook, 2ndEd.   (cargo-cult of a higher order?)

$directory =~ s< ^ /? # match leading '/' if present ( # capture what is between ends [^/]* # match anything not a '/' (?: # might be a '/', (?! /$ ) # but don't allow a '/' at EOL . # okay, eat the '/' ) * ) /? $ # match trailing '/' > </$1/>x; # now surround the middle with '/'
Update:   I take too long typing!   And my solution only takes one '/' off each end.   I guess I took so long typing that "I forgot the question"   ;-)