To get at each field, we can split when we see a colon:
#!/usr/bin/perl
use warnings;
use strict;
my $passwd = "A:B:1:2::/dir:/bin/bash";
my @fields = split /:/, $passwd;
print "Login name : $fields[0]\n";
print "User ID : $fields[2]\n";
print "Home directory : $fields[5]\n";