use strict; use warnings; my $str; while (1) { print "Please enter the number.(Enter exit at the end) "; $str = ; chomp $str; if ($str eq "exit" || $str eq "") { last; } if ($str =~ /[a-zA-Z]/) { print "Not number.\n"; next; } print (abs($str), "\n"); };