use File::Basename; my $name = basename($file_with_path2,'.out','.some_other_ext'); print "$name\n";