open BINFILE, "<", "somefile.txt" or die $!; ReadBytes( $num, \*BINFILE ); sub ReadBytes { my ( $num, $binfile ) = @_; return undef if $num < 1; my @bytes; for (1..$num) { my $byte; read($binfile, $byte, 1); push @bytes, unpack("C",$byte); } return @bytes; }