sub bin2hex { my $line = $_[0]; my $lenCount = 4; my $hexLine = ""; my $width = '4'; while ( length($line) % $width != 0) { $line = '0' . $line; } while ($lenCount <= length($line)) { my $x = substr ($line, -($lenCount), $width); $hexLine = sprintf("%X", oct("0b$x")).$hexLine; $lenCount += 4; } print "In bin2hex: $line\nAfter bin2hex: $hexLine\n\n"; return $hexLine; }