#!/usr/bin/perl use warnings; use strict; my $match; my @match = (); push (@match, $match); # I fear this is what I'm doing wrong - I'm not putting $match in @match correctly. @match = (-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); my $value = abs($match); # Here I'm trying to establish a variable that will basically be the absolute value of the fourth column of my input file, this is what I want to match. open my $target, '>', "test-out-$value" or die $!; open my $FILE, '<', 'input_file' or die $!; while (<$FILE>) { chomp; my @columns = unpack('a8 a8 a8 a6'); #print join(" ",map {$_} @columns), "\n"; #print "@columns[3] \n"; foreach (@columns[$#columns]) { if ($_ =~ /$value/) { my $ID = $_; my $IDform = sprintf ("%4s", $ID); # Also here I'm confused and I can't think about how to write what I want. I want to match the absolute value (a few lines above), but print the actual value (in my output file), not the absolute one. This worked easily in my first code (where I matched for specific number) but now I can't think how to write the general version. my $currentline = $.; my $currentlineform = sprintf ("%7s", $currentline);## my @selection = (@columns[0..$#columns-1]); my $layout = "%10s"x(@selection) . "\n"; printf $target $IDform . $currentlineform . $layout, @selection; } } }