use strict; use warnings; my %is_valid_type = do { my $i = 1; map { $_ => 10 * $i++ } qw( KB MB GB ) }; print "Enter the pathname and filename of the file to split: "; my $filename = ; chomp($filename); my %block = map { $_ => undef } qw( size type amount ); while (1) { print "Enter the block size \n (example: 400KB,10MB,1GB): "; chomp($block{size} = ); @block{qw(amount type)} = ($block{size} =~ m/^\s*([\d.]+)\s*([a-zA-Z]{2})\s*$/); $block{type} ||= 'KB'; $block{type} = uc $block_type; unless ( $is_valid_type{$block{type}} ) { print "Invalid block type specified!\n\n"; next; } $block{size} = 2 ** $is_valid_type{$block{type}}; last; }