#!/usr/bin/perl use strict; use warnings; open my $data_fh, '<', 'data.txt' or die "could not open data.txt: $!\n"; open my $dollar_fh, '>', 'dollar.txt' or die "could not open dollar.txt: $!\n"; open my $star_fh, '>', 'asterisk.txt' or die "could not open asterisk.txt: $!\n"; open my $percent_fh, '>', 'percent.txt' or die "could not open dollar.txt: $!\n"; while( <$data_fh> ){ chomp; while( length ){ if( s{ (\d+) \$ }{}msx ){ my $len = $1; my $data = substr( $_, 0, $len, '' ); print $dollar_fh "$data\n" or die "could not print to dollar.txt: $!\n"; } if( s{ (\d+) \* }{}msx ){ my $len = $1; my $data = substr( $_, 0, $len, '' ); print $star_fh "$data\n" or die "could not print to asterisk.txt: $!\n"; } if( s{ (\d+) \% }{}msx ){ my $len = $1; my $data = substr( $_, 0, $len, '' ); print $percent_fh "$data\n" or die "could not print to percent.txt: $!\n"; } } } close $dollar_fh or die "could not close dollar.txt: $!\n"; close $star_fh or die "could not close asterisk.txt: $!\n"; close $percent_fh or die "could not close percent.txt: $!\n"; close $data_fh or die "could not close data.txt: $!\n";