if(length $foo > 1 and substr($foo,-1,1) ne '/') { $foo .= '/'; } #### $foo .= '/' unless($foo =~ m/\/$/);