# like this: (my $newfile = $filename ) =~ s{.*[\\/]}{}; # if there is no (back)slash, $newfile will be same as $filename # or like this: my @path = split /[\/\\]/, $filename; my $newfile = pop @path; # or use File::Basename, if that's appropriate to your needs