use warnings; use strict; use Data::Dump; my @trip = ("Chicago", "Saint Looey", "Joplin", "OKC", "Amarillo", "Gallup", "Flagstaff", "Winona", "Kingman", "Barstow", "San Bernandino", "LA"); my %cities = ( "Amarillo" => { state => "TX" }, "Barstow" => { state => "CA" }, "Chicago" => { state => "IL" }, "Flagstaff" => { state => "AZ" }, "Gallup" => { state => "TX" }, "Joplin" => { state => "MO" }, "Kingman" => { state => "AZ" }, "LA" => { state => "CA" }, "OKC" => { state => "OK" }, "Saint Looey" => { state => "MO" }, "San Bernandino" => { state => "CA" }, "Winona" => { state => "AZ" }, ); for my $i (0..$#trip-1) { my ($from,$to) = @trip[$i,$i+1]; print "$from, $cities{$from}{state} to $to, $cities{$to}{state}", $cities{$from}{state} ne $cities{$to}{state} ? " - Mann Act!" : (), "\n"; } print "\n##### Alternative #####\n"; $cities{$_}{city} = $_ for keys %cities; $_ = $cities{$_}//die("bad city $_") for @trip; dd \%cities, \@trip; for my $i (0..$#trip-1) { my ($from,$to) = @trip[$i,$i+1]; print "$from->{city}, $from->{state} to $to->{city}, " ."$to->{state}", $from->{state} ne $to->{state} ? " - Mann Act!" : (), "\n"; }