Take the 2-minute tour ×  I was wondering if there is a way to
convert a number like  100u     10km     300nm      and so on
so that they are interpreted as:  100*10^-6      10*10^3
300*10^-6  I need to compare this numbers (100u 10km etc). For
example if I want to compare 100u to 10u that's ok I just do the
following, which is not correct but does the job:  $distance =~
s/(.*)u/$1/; if ($distance >= $desired_distance) {        printf
$distance;  where (.*) u is the number eg 100u. So i just remove
the "u" and then compare it with a number.  But what about if I
have the number   and I want to compare it with   The above
thing wouldn't help.  share|improve this question add comment  3
Answers  up vote 7 down vote accepted  If there’s no CPAN module
for that you can always roll your own:  my %units = (     m  =>
1,     km => 1000,     mm => 0.001,  for my $num (qw(10 10km
10mm)) {     $num =~ /(\d+)(\w+)?/;     my $value = $1;     my
$unit  = $2 || 'm';     print "$num = ", $value*$units{$unit}, "
m\n";