#!/usr/bin/perl -w use strict; #basic "command loop" while ( (print "Enter a command: "), (my $line = ) !~ /^\s*q(uit)?\s*$/i ) { #### Validate input and if ok, call a sub at the #### of validation next unless $line =~ m/\S/; #chomp ($line); #actually optional here (\n counts as $) if ($line =~ m/^\s*help\s*$|^\s*h\s*$/i) { print "there is no help for the helpless!!!\n"; next; } if ($line =~ m/^\s*[+-]{0,1}\s*\d+\s*$/) { print "wow, a number! try again!\n"; next; } if ($line !~ m/^add$|^del$/i) { print "invalid_command!!\n"; next; } add() if $line =~ m/add/; del() if $line =~ m/del/; } sub add { print "some kind of add happend\n";} sub del { print "some kind of del happened\n";} __END__ Some example interaction: C:\TEMP>perl stdcommandloop.pl Enter a command: 34 wow, a number! try again! Enter a command: -45 wow, a number! try again! Enter a command: +-56 invalid_command!! Enter a command: Enter a command: Enter a command: help there is no help for the helpless!!! Enter a command: Enter a command: del some kind of del happened Enter a command: add some kind of add happend Enter a command: quit > (OS prompt is back, end of program)