#!/usr/local/bin/perl use strict; use warnings; my %conv = (k => 1000, kb => 1024, g => 1000000, gb => 1024 * 1024); # Note that the keys are sorted to put the longer # matches first in the regex my $keys = join '|', sort { length $b <=> length $a } keys %conv; while () { print "$_ -> "; s/(\d+)($keys)/$1 * $conv{$2}/e; print "$_\n"; } __END__ 30k 30kb 10g 10gb