use File::Basename qw(dirname); print dirname($string);