my $months = $dbh->selectall_arrayref("select to_char(last_day(add_months('14-May-2004', (rownum-1))),'MON-RRRR') dt from all_objects where rownum <= months_between(sysdate,'31-May-2004')+1"); my $month; my $monthhash; my $i = 0; # populate month hash with zero's for now (this may need to be done later) foreach $month (@$months) { $monthhash{@$month[0]} = $i; # print "pop @$month[0] $i\n"; $i++; } for($i=0; $i<$#$months; $i++) { print "hope 1 @{$months->[$i]}\n"; print "hope 2 $monthhash{trim(@{$months->[$i]})}\n"; print "hope 2A $monthhash{@{$months->[$i]}}\n"; } sub trim { my @out = @_; for (@out) { s/^\s+//; #trim left s/\s+$//; #trim right } return @out == 1 ? $out[0] #only one to return : @out; #or many }