#!/usr/bin/perl -w use strict; my $now = 8; # we'll pretend it's between 8 and 9 PM my @hours; my %url = ( monday => { 1 => "Too early in the morning", 3 => "Someone came home from a bender", 7 => "Time for coffee", 16 => "Need to slack off the last hour of work" } ); # begin awkward code @hours = reverse (sort {$a <=> $b} keys %{$url{"monday"}}); foreach (@hours) { $now = $_, last if $_ <= $now; } # end awkward code