#!/usr/bin/perl -w use strict; my %ttys_of; foreach (`who`) { my ($user, $tty) = /(\S+)\s+(\S+)/; push @{$ttys_of{$user}}, $tty; } foreach my $user (sort keys %ttys_of) { my $ttys = $ttys_of{$user}; if (@$ttys == 1) { print "user $user is ONLY logged in at one place $ttys->[0]\n"; } else { print "user $user is logged in at: " . join(' ', sort @$ttys) . "\n"; } }