in reply to sort a hash with split values

Well, you could just dump the usernames into state buckets and then retrieve them by state:
use strict; use warnings; my (%hash, %states); while (<DATA>) { chomp; @_ = split /: /, $_, 2; $hash{$_[0]} = $_[1]; } for (keys %hash) { push @{$states{(split /:/, $hash{$_})[1]}}, $_; } for (sort keys %states) { print $hash{$_}, "\n" for @{$states{$_}}; } __DATA__ alpha: 12:NY:me@yoiu.com beta: 13:MO:fg@yoiu.com gamma: 14:DE:fghh@yoiu.com delta: 15:MO:adf@yoiu.com epsilon: 16:DE:mjhg@yoiu.com iota: 17:NY:juyu@yoiu.com eta: 18:NY:mjhk@yoiu.com
The transform method is so much neater, though.