#!/usr/bin/perl use strict; use warnings; # 848449 =head OP says: Question is u have a file A ACEEWSMKIIWSDJDWKDKEKSSAQWE and want to extract lines with option 5-10 with output like SMKII ## ww reads this as: I have a file with lines like ACEEWSMKIIWSDJDWKDKEKSSAQWE 012345678901234567890123456789 0 1 2 and want to extract characters at positions, 5 .. 9, where the character position is 0-based. =cut if ( $#ARGV < 2 ) { print "Usage: extract.pl firstLine lastLine filename\n"; exit 1; } my $start = $ARGV[0]; my $stop = $ARGV[1]; my $file = $ARGV[2]; my ($line_elements, @line_elements); open (FILE, '<', $file) or die "Can't open file $file $!"; while () { my $line = $_; my @line_elements = split (//,$line); my (@wanted, $wanted); for ($start .. ($stop-1) ) { push @wanted, $_; } for $wanted(@wanted) { for ($line_elements[$wanted]) { print "$line_elements[$wanted]"; } } print "\n\tNext line in file: \n"; }