my @out = map { (split /%/)[2] } sort map { my @field = split /,/; "$dow{$field[7]}%$field[8]%$_" } @in ;