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