use strict; my $out = "12315141800F1F5F3F3F63410026DE8F45"; for my $hex ($out =~ /(\S{2})/g) { # split the strings into chunks of two chars printf "hex => %s, binary => %08B\n", $hex, hex($hex); }