That is great use of the Perl built in function 'index'. Let me introduce you to another Perl built in function. This one is called 'split'.
To read the password file try something like this code..
open my $passwdfh, "<", "/etc/passwd" or die "couldn't open the passwo
+rd file: $!\n";
while (<$passwdfh>) {
next if /^\s*#/; # comments in the password file?
chomp;
my ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split /:/;
# do stuff with the entries from the password file now ...
next if $uid < 1000; # .. for example.
}
close $passwdfh;