my $path = 'c:\\path\\file'; # The path and file name my $filename = (split (/[\/\\]/, $path))[-1]; # Split on / and \, and then get the last element