$string = 'http://www.whatever.html/directory/'; $string .= 'index.html' if(substr($string, -1) eq '/');