use warnings 'all'; use strict; use autodie; open my $input, '<', $ARGV[0]; open my $out, '>', 'hex.txt'; while (my $sentence = <$input>) { my $substring = '...pck.*?\.c'; $sentence =~ s{$substring}{}; print $out unpack 'H*', $sentence; }