use File::Basename; $filename = '/home/user1/test.txt'; $name = dirname($filename); # $name = '/home/user1'