help with perl while loop

Can anyone tell me why this program won't kick out when the time gets beyond time in the loop?

sub showtime
{
local($format,$military)=@_;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

if \(\(! $military\) && \($hour > 12\)\) \{$hour-=12;\}
$min=sprintf\("%02d",$min\);
$sec=sprintf\("%02d",$sec\);
$format =~ s/SS/$sec/g;
$format =~ s/HH/$hour/g;
$format =~ s/MM/$min/g;
return $format;

}
printf &showtime("The Time is Now HHMM\n",1);
while ($showtime le 2345)
{
while ($x==0 )
{
if (-e $legrun)
{
$x=0;
sleep 10;
}
else
{
$x=1;
}
}
$x=0;

As far as I can see the variable $legrun appears only once in your script, so the statement:

if ( -e $legrun) {
...

will never be true. You should define the filename before you check for its existance.

I figured it out, it was actually because I was not formatting showtime

while (&showtime(HHMM, 1) < 1422)

Thanks