use File::Basename; print dirname $0; #### print $0 =~ /(.*)\\/; # or if you want the trailing backslash print $0 =~ /(.*\\)/;