#!/usr/bin/perl use warnings; use strict; open (my $fh, "< test.txt") or die "$!\n"; #input file open (my $oh, "> $0-out.txt") or die "$!\n"; #output file my $script = '/home/whoever/bin/myscript.pl'; while (<$fh>){ my $string = $_; # strip off trailing
and anything after it $string =~ s/
.*$//; #strip whitespace at end in case space preceded the
$string =~ s/\s+$//; ## split on space my @words = split / /, $string; #print join "\n",@words,"\n"; my $lastword = $words[-1]; print $oh "$script $lastword\n"; }