my $file = 'c:\folder1\filename.doc'; $file =~ s{ # Substitue... \\ # a backslash [^\\]* # zero or more not-backslashes $ # at the end of string } {}x; # with nothing # allow comments & spaces in search-pattern print $file; # c:\folder1