in reply to how do I remember the trailing /

look at perlfunc:substr (particularly the negative examples)

also, look at perlre(to see what $ means in a regex), and perlop (for the m/// operator)

which should lead you to something like:

if(length $foo > 1 and substr($foo,-1,1) ne '/') { $foo .= '/'; }
or
$foo .= '/' unless($foo =~ m/\/$/);
btw - if you aren't used to the unless syntaxt above, see perlsyn