use File::Basename; my $dirname = dirname ("lib/this/that/other.txt"); #### ($path, $filename) = $fullpath =~ m/^(.*[/\\])([^/\\]+)/;