in reply to Changing file names as they are uploaded

How about a one-liner...

$imagename =~ s/^(.*?)(\.\w*)$/my $temp = $2; ($_ = $1) =~ s!\W!_!g; $ +_ .= $temp/e;

It deals with your examples plus the most pathological tests I could think of.

#! perl -sw use strict; my @filespecs = map{ $_ =~ s/^(.*?)(\.\w*)$/my $temp = $2; ($_ = $1) = +~ s!\W!_!g; $_ .= $temp/e; $_} <DATA>; print $_, $/ for @filespecs; __DATA__ me~swimming.jpg J.R,ewing.jpg A¬!£$%^&*()-_+={}[]'@;:~\#\"<>,./|\?.jpg pic.

Output

C:\test>199139 me_swimming.jpg J_R_ewing.jpg A___________________________________.jpg pic. C:\test>

Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!