#!/usr/bin/perl use strict; # strict and warnings are your friends. USE THEM ALWAYS! use warnings; # 923876 my $num; input(); # you need not dump all your functions into subs # and certainly not into chained subs, but using chained subs # here makes it easier for me to point out a few things =head print "\n Press any key to exit"; # Utterly unnecessary - # your program will exit when it runs out of $key = ; # instructions, absent code to specifically do # otherwise ... such as sub quit_or_repeat: #End of Program =cut sub input { print "Enter an integer that is between 0 and 9: "; # no newline so user can chomp ($num = ); # enter data at prompt test_input(); } sub test_input { if ( $num =~ /^[1-8]$/ ) { # 1...8 are the numbers "between 0 and 9" # as spec'ed by the prompt in OP's code main(); } else { print "Only single-digit, positive integers, 1 - 8, are allowed\n"; input(); } } sub main { for(my $i=1; $i<=$num; $i++) { print "$i "; } print "\n"; quit_or_repeat(); # sub called here actually does something # contrast w/ the original "$key = # # End of Program" } sub quit_or_repeat { my $key = ''; print "\n Press 'q' to quit or any other key to continue: "; chomp ($key = ); if ( lc($key) eq 'q' ) { # either 'q' or "Q" quits exit; } else { input(); # go another round } }