format_c@linux:~/perl_samples> perl my $var = "/windows/d/Perl/test/a3/5/23/7"; $var =~ s%\D*(\d+)/%$1-%g; $var .= ".txt"; print $var,"\n"; 3-5-23-7.txt format_c@linux:~/perl_samples>