#!/usr/bin/perl print "Content-type: text/plain\n\n"; use strict; use CGI::Carp qw(fatalsToBrowser); use Validate; my $the_time = "12:23 pm"; Validate::val_time($the_time); $the_time = $Validate::val; if ($the_time) { print "$the_time\n" } else { print "error\n" } #### package Validate; # use package to declare a module our $val; sub val_time { $val = shift; $val = ($val =~ /^(\d{2}):(\d{2}) (am|pm)$/) ? "$1:$2 $3" : 1; return $val; #worked with and without this line } 1;