$string = "perl345"; for( reverse split //, $string ){ $newstring .= chop unless /[a-z]/ } print scalar reverse $newstring;