in reply to converting "30k" string to integer

My attempt uses the fact that "gb" means "1024 ** 3", whereas "g" means "1000 ** 3", so there is just a diffrence in the bases, whereas the exponents are the same. I just store the single-letter exponent identifiers in a hash as keys with their corresponding exponents as values and do the same with the base identifiers ("" for decimal and "b" for binary) and then do the rest with a regex:
#!perl -ws my %exponents = ( 'k' => 1, 'm' => 2, 'g' => 3, 't' => 4 ); my %bases = ( '' => 1000, 'b' => 1024 ); while (<DATA>) { chomp; my $old = $_; s<(\d+)([a-zA-Z])([a-zA-Z]?)\b> < (defined $exponents{lc($2)} and defined $bases{lc($3)}) ? # suff +ix recognized ? $1 * ($bases{lc($3)} ** $exponents{lc($2)}) # substitute if y +es : "$1$2$3" # otherwise just +leave it >eg; print "`$old' became `$_'\n"; } __DATA__ My dog makes $30k a year. I own a 20gb hard drive. The budget deficite is $10g. 18h is 24d.
The output is as expected (the last data line does not change).