$num = '654,321'; if ( $num =~ /^\d{1,3}(,\d{3})*$/ ) { $num =~ y/,//d; # delete commas } else { # not a conforming number }