in reply to test value of a field for 1 line in passwd

I am copying the passwd file from the remote system

Which means that you are transmitting a plain text file, containing user names and passwords, over the internet?



if (grep {$fields[3] !~ /5612/} @fields) {

Without anchors your regular expression will also match numbers like 15612, 25612, etc.    It would be better to look for an exact match.    And you don't need grep because you are only testing $fields[3] and not all the elements of @fields.    (For example, if @fields contains ten elements then you are testing $fields[3] !~ /5612/ ten times, and each time will produce the same result.)

if ( $fields[ 3 ] ne '5612' ) {

Or:

if ( $fields[ 3 ] != 5612 ) {

Or:

if ( $fields[ 3 ] !~ /\A5612\z/ ) {