if ( $filename =~ /(.*)(\d+)\.(.*)$/ ) { $prefix = $1; $digit = $2; $suffix = $3; } else { print "Error etc\n"; }