use Regexp::Common; my %units = map ($_,1), qw[ miles kilometers pounds kilograms ... ]; my( $num, $from, $to ) = getUserInput(); die 'Bad number input' unless $num =~ /^\s*$RE{num}{real}\s*$]; die 'Bad units input' unless exists $units{ lc $from } and exists $units{ lc $to ); my $res = `units $num $from $to`;