in reply to converting "30k" string to integer

I'd go for something like this (untested):

my %abbr = ( 'k' => 1e3, 'kb' => 1 << 10, 'g' => 1e9, 'gb' => 1 << 30, ); my $match = join '|', keys %abbr; ... and later $text =~ s/(\d+)($match)\b/$1 * $abbr{lc $2}/gie;

Note that since the pattern requires a word boundary following the abbreviation, it doesn't matter that the alternatives might try to match "k" before "kb". (Otherwise it would have needed a way to avoid that, eg by sorting the keys in reverse ASCII order.)

If you need to cope with more than just integers, it'd probably be worth looking in Regexp::Common for a way to match the numbers you want.

Hugo