use strict; use warnings; my %convert = ( KB => 10, MB => 20, GB => 30 ); my $num; { print "Enter the block size\n (example: 400KB,10MB,1GB): "; my $block_size = uc ; print "Invalid block type specified!\n\n" and redo unless $block_size =~ /^(\d+)([KMG]B)$/; $num = $1 * 2 ** $convert{$2}; } print $num;