use File::Basename; # it's in the core distribution $canonical =~ tr{\\}{/}; # if the path separator is \ and not / my $filename = basename( $canonical );