my %cardinal = ( 1 => '1st', 2 => '2nd', 3 => '3rd', map { $_ => "${_}th" } 4 .. 9 ); print $cardinal{$digit};