for my $a () { substr($a,-7)=" "; # <<< here #### substr($a,-7)= ""; # empty string! # or let the os handle the path $a .= '/..';