use strict; use warnings; my $inp = getInput('Enter two values'); $inp = [split /[\s,]+/, $inp]; print "Values entered are: $inp->[0], $inp->[1]\n"; sub getInput { my $inp; while (1) { print "$_[0]: "; chomp($inp = ); return $inp if $inp; } }