#!/usr/bin/perl -w use strict; while() { my $dot_ix = index $_ ,'.'; printf "%40s: %s\n", "the string before trimming", $_; printf "%40s: %s\n", "dot+", substr $_, $dot_ix; printf "%40s: %s\n", "dot-2", substr($_, $dot_ix - 2); printf "%40s: %s\n", "trimmed fat", substr($_, $dot_ix - 2, $dot_ix -1, ''); # $dot_ix -1 since it's the num of chars, not index printf "%40s: %s\n", "the string after trimming", $_; } __END__ 1996.40637 1996.41064 1996.41199 1996.41467 1996.41882