Join strings
#!/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"; my $passwd2 = join "#", @fields; print "Original password : $passwd\n"; print "New password : $passwd2\n";